Share via


CMemoryState::DumpStatistics

voidDumpStatistics()const;

Remarks

Prints a concise memory statistics report from a CMemoryState object that is filled by the Difference member function. The report, which is printed on the afxDump device, shows the following:

  • Number of “object” blocks (blocks of memory allocated using CObject::operator new) still allocated on the heap.

  • Number of nonobject blocks still allocated on the heap.

  • The maximum memory used by the program at any one time (in bytes).

  • The total memory currently used by the program (in bytes).

A sample report looks like this:

0 bytes in 0 Free Blocks
8 bytes in 2 Object Blocks
0 bytes in 0 Non-Object Blocks
Largest number used: 8 bytes
Total allocations: 8 bytes
  • The first line describes the number of blocks whose deallocation was delayed if afxMemDF was set to delayFreeMemDF. For more information, see afxMemDF, in the “Macros and Globals” section.

  • The second line describes how many object blocks still 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.

Example

The following code should be placed in projnameApp.cpp. Define the following global variables:

static CMemoryState oldstate, newstate, diffstate;

In the InitInstance function, add the line:

oldstate.Checkpoint();

Add a handler for the ExitInstance function and use the following code:

   newstate.Checkpoint();
   if (diffstate.Difference(oldstate, newstate))
      {
      TRACE("Memory leaked\n");
      diffstate.DumpStatistics();
      }
   return 0;

You can now run the program in Debug mode to see the output of the DumpStatistics function.

Output

Memory leaked
0 bytes in 0 Free Blocks.
-626 bytes in -13 Normal Blocks.
0 bytes in 0 CRT Blocks.
0 bytes in 0 Ignore Blocks.
-1212 bytes in -6 Client Blocks.
Largest number used: 178 bytes.
Total allocations: 988 bytes.

CMemoryState OverviewClass MembersHierarchy Chart