次の方法で共有


Dumping Memory Statistics

The CMemoryState member function Difference determines the difference between two memory-state objects. It detects any objects that were not deallocated from the heap between the beginning and end memory-state snapshots.

To dump memory statistics

  • The following example (continuing the example from the previous topic) shows how to call DumpStatistics to get information about the objects that have not been deallocated:

    if( diffMemState.Difference( oldMemState, newMemState ) )
    {
        TRACE( "Memory leaked!\n" );
        diffMemState.DumpStatistics();
    }
    

    A sample dump from the example above is shown here:

    0 bytes in 0 Free Blocks
    22 bytes in 1 Object Blocks
    45 bytes in 4 Non-Object Blocks
    Largest number used: 67 bytes
    Total allocations: 67 bytes
    
    • The first line describes the number of blocks whose deallocation was delayed if afxMemDF was set to delayFreeMemDF. For a description of afxMemDF, see the procedure “To select specific memory diagnostic features with afxMemDF” presented under Memory Diagnostics.

    • The second line describes how many objects remain allocated on the heap.

    • The third line describes how many nonobject blocks (arrays or structures allocated with new) were allocated on the heap and not deallocated.

    • The fourth line gives the maximum memory used by your program at any one time.

    • The last line lists the total amount of memory used by your program.

For more information, see Dumping All Objects, Tracking Memory Allocations, , and .