|
From: David E. <tw...@us...> - 2003-10-23 12:05:46
|
Quoting Attila <sa...@fr...>:
> Hello,
>
> I got warning to the simple code below (exc.cpp) if I link
> the pthread library like
>
> gcc exc.cpp -lpthread -lstdc++
>
> (-D_REENTRANT omitted for simplicity). No problem if I don't
> link pthread like
>
> gcc exc.cpp -lstdc++
>
> I guess the libraries are linked dinamically because the
> executable is only 37K.
>
> #include <iostream>
>
> class Exception
> {
> public:
> int _type;
> Exception(int i) : _type(i) {}
> };
>
>
> int main()
> {
> try {
> throw new Exception(5);
If you use this...
throw Exception(5);
> } catch(Exception* e) {
..and this...
catch (Exception& e)
> std::cout << "gotcha! " << e->_type << std::endl;
> delete(e);
..then you won't have to delete the object.
> }
> return 0;
> }
>
--
\David
|
|
From: Attila <sa...@fr...> - 2003-10-30 13:01:47
|
Hi, Thanks for the answers for you all. Though I am afraid to continue with my newbie questions. I (after reading a bit of manual) still do not understand what this 'still reachable' is used for. file:///usr/local/share/doc/valgrind/mc_main.html 3.1 Kinds of bugs that memcheck can find <...> All reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. <...> 3.2 Command-line flags specific to memcheck <...> --show-reachable=no [default] --show-reachable=yes <...> When enabled, the leak detector also reports on blocks which it could find a pointer to. Your program could, at least in principle, have freed such blocks before exit. 'could have freed'? Where this uncertainty comes from if "calls to malloc/new/free/delete are intercepted"? How can I make sure that they are freed for sure? In other words how can I get rid of the still reachable message if possible in this case and in general? Thanks for David for the advice on C++ exceptions, too. BR, Attila |
|
From: Nicholas N. <nj...@ca...> - 2003-10-30 13:13:58
|
On Thu, 30 Oct 2003, Attila wrote: > 'could have freed'? Where this uncertainty comes from if > "calls to malloc/new/free/delete are intercepted"? 'could have freed' means that they weren't lost -- ie. you still had pointers to them in scope -- but that you didn't free them. > How can I make sure that they are freed for sure? Actually free them. > In other words how can I get rid of the still reachable > message if possible in this case and in general? Reachable memory isn't necessarily bad. Eg. if you have malloc'd blocks that are used right up until your program ends, there's not much point manually freeing them; that will just take time. N |