Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Testing for Memory Leaks in the Zip Library
Discusses the often-mistaken case of memory leaks in the Chilkat C++ library. // The Chilkat C++ library creates some "stay-resident"
// structures on an as-needed basis that are not deallocated.
// (They are deallocated from within CkSettings::cleanupMemory which can be
// called once at the end of your program.)
// The stay-resident structures exist for performance reasons.
// As an example, the CkZip class will initialize and
// keep huffman encoding tables in memory the first time it is called.
// To check for memory leaks, make sure all Chilkat objects have been destructed
// and *then* call CkSettings::cleanupMemory. One caveat: once CkSettings::cleanupMemory
// has been called, the program should *not* create any more Chilkat objects.
// Also, if you want to check for memory leaks, do not declare any Chilkat objects
// as global variables. Global variables are destructed *after* the program's mainline
// has exited, so there is no way to call CkSettings::cleanupMemory after all Chilkat objects
// have been destructed.
void TestZip(void)
{
// Open a Zip and unzip it to the testDir subdirectory.
CkZip zip;
zip.UnlockComponent("Anything for 30-day trial");
zip.OpenZip("test.zip");
zip.Unzip("./testDir",0);
zip.CloseZip();
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// When TestZip returns, the Chilkat object(s) have been destructed, so we can
// now call cleanupMemory.
TestZip();
CkSettings::cleanupMemory();
// At this point in the code, there should be no memory leaks...
return 0;
}
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.