Chilkat
XML Parser Memory Usage
for Visual C++ Applications
The
Chilkat VC++ libraries use caching techniques for efficient string
processing, and these may appear to be memory leaks when in fact
they are not. One way to diagnose a real memory leak is to place
code within a tight loop and run it many times, and then watch
to see if the memory continually increases. If it does not, then
there is no memory leak.
However,
Chilkat understands that VC++ programmers like to debug memory
leaks in their own code, and so we have provided a mechanism where
the Chilkat caching and static internal resource can be "cleaned
up". The CkSettings class can be used to achieve this:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CkXml *xml = new CkXml;
xml->LoadXmlFile("something.xml");
delete xml;
// Clean up memory resources within the Chilkat library
// that are not normally deleted until program shutdown.
// This should only be called when there are no other
// Chilkat objects remaining to be destructed.
CkSettings::cleanupMemory();
return 0;
}
One
must be very careful in using CkSettings::cleanupMemory, because
it should only be called when there are no other Chilkat objects
remaining to be destructed. The following code may crash on exit
because it calls cleanupMemory, and the local CkXml object is
not destructed until after WinMain exits.
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CkXml xml;
xml.LoadXmlFile("something.xml");
// This is an error because the CkXml object has not yet been
// destructed.
CkSettings::cleanupMemory();
return 0;
}