11.20. How do I use CMemoryState?

In MFC 2.0 and above built in diagnostic facilities are provided. Hence it is not necessary to include CMemoryState explicitly in your app. The MFC version 2.0 debugging libraries automatically perform memory leak detection. The detection code is in AFXMEM.CPP. This code detects the case in which an application dynamically allocates an object and fails to delete the object before the program terminates.

In fact,CMemoryState may not function properly. You can refer to the following article in KB(Go MDKB in CIS) for more details:

ID:Q99022 "Foundation Class Debug Library Detects Memory Leaks"

#define new DEBUG_NEW should be defined in every .CPP source file. Also, insert the following code in InitInstance of the application:

#ifdef _DEBUG
    afxMemDF |= checkAlwaysMemDF;
#endif

You can refer to the following article in KB for more details:

ID: Q117326, Foundation Classes Common Asserts, Causes and Solutions.

Muniraju, netquest, MSMFC, 8/1/95