Dumping All Objects

DumpAllObjectsSince dumps out a description of all objects detected on the heap that have not been deallocated. As the name implies, DumpAllObjectsSince will dump all objects allocated since the last Checkpoint. However, if no Checkpoint has taken place, all objects and non-objects currently in memory will be dumped.

·To dump all objects:

Expanding on the code from the previous example, the following code dumps all objects that have not been deallocated when a memory leak is detected:

if( diffMemState.Difference( oldMemState, newMemState ) )

{

TRACE( "Memory leaked !\n" );

diffMemState.DumpAllObjectsSince();

}

A sample dump from the previous code is shown as follows:

Dumping objects ->

{5} string.cpp(62) : non-object block at $00A7521A, 9 bytes long

{4} string.cpp(62) : non-object block at $00A751F8, 5 bytes long

{3} string.cpp(62) : non-object block at $00A751D6, 6 bytes long

{2} a CPerson at $51A4

Last Name: Smith

First Name: Alan

Phone #: 581-0215

{1} string.cpp(62) : non-object block at $00A7516E, 25 bytes long

The numbers in braces at the beginning of most lines specify the order in which the objects were allocated. The most recently allocated object is displayed first. You can use these ordering numbers to help identify allocated objects.