log4cpp ver 0.3.4b on MSVC++6 SP5
The MS debug crt memory leak checker reports that the
HierarchyMaintainer and Appender classes are leaking
memory. It appears to be the result of the
implementation of the Singleton pattern.
The HierarchyMaintainer has a single static
HierarchyMaintainer* that is initialized the first time
static getDefaultMaintainer is called. This object is
created on the heap, but I don't think its destructor
is ever called.
Here is an alternate way of implementing the Singleton
pattern:
- remove the static HierarchyMaintainer* from the class
definition
- change getDefaultMaintainer to:
HierarchyMaintainer&
HierarchyMaintainer::getDefaultMaintainer() {
static HierarchyMaintainer self;
return self;
}
With the above implementation, the c++ runtime will
call self's destructor as the application is shutting
down. Since it is a function-local static, only one
will ever be created.
The Appender::AppenderMap& Appender::_getAllAppenders()
suffers from a similar bug.
I ran the testCategory.cpp test after making these
changes and it seems to be fine. This resolves most of
the memory leaks I was detecting.
The NDC class also appears to be leaking, but it is
more complicated and I did not have time to try and
figure out what was going on.
Hope this helps. Many thanks for all the work you've
done on a handy logging system.
Logged In: YES
user_id=233843
Hi Colin,
I'm wondering wether you've received any comment to your
suggestions which is not available via SourceForge?
Also I'm interested if you've invested more time to get
around the NDC problem?
Thanks
Michael