Boost logo

Boost Users :

From: Christopher Woods (cwoods_eol_at_[hidden])
Date: 2007-05-29 10:06:24


Seweryn Habdank-Wojewódzki wrote:
> Hi
>
>> 'possibly lost' seems less than conclusive that there's actually a leak.
>
> Yes I know, but sometimes it is possible to eliminate them completely, even
> if "variable" exists until the end of the program.
>
> Especially If the program is written in C++. In C++ where you have RAII, and
> you can control static initialisation and destruction there is an opportunity
> to release all resources.
>
> Some months ago I have developed simple logger (http://cxxtl.sf.net) and there
> I had a problem that resources of logger HAVE TO stay in memory until the
> last usage of logger is finished even if it is in statically allocated class
> destructors.
>
> Logger produce something like below.
>
> foo.cpp [7] : Creation of the foo object.
> main.cpp [30] : Trivial logger in main().
> ...
> main.cpp [12] : atexit()->finalize()->EXIT_SUCCESS
> foo.cpp [12] : Destruction of the foo object.
>
> Logger observe atexit function.
> Logger even can observe final destructions.
>
> And valgrind do not report any leak:
>
> ==24722== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 1)
> ==24722== malloc/free: in use at exit: 0 bytes in 0 blocks.
> ==24722== malloc/free: 8 allocs, 8 frees, 8,870 bytes allocated.
> ==24722== For counts of detected errors, rerun with: -v
> ==24722== All heap blocks were freed -- no leaks are possible.
>
> So sometimes it is possible to eliminate possible leaks (cause they are at the
> end of the program). If in your case it is possible to eliminate this from
> the code I willbe grateful for that, if not, I understand, because In my
> logger I had similar problem.
>
> Best regards.
>

I think that's a bit different than the case you are seeing now. The
facet is attached to cout. So you have to look at when is cout
instantiated and released in comparison to valgrind's instrumentation.

If you want to try to confirm it as a leak - change your cout references
to a [non-static] stream you declare directly in your program scope (not
cout, cerr, clog). You should then either see the "possible" move to
"leaked" or go away entirely.

HTH,

-Chris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net