Figure 1: Redefining global operator new and delete, and new- and delete-expressions to keep track of allocation/deallocation

// The inlined new operator
inline void* AFX_CDECL 
operator new(size_t nSize, char* pszFileName, int nLine)
{
   // Allocate memory and keep track of it.
        . . .
}

// The inlined delete operator
inline void AFX_CDECL operator delete(void* pData)
{
// Deallocate memory and loose track of it.
. . .
}

// Make sure that the global new and delete operators are being 
// used. Also take advantage of the "#define new DEBUG_NEW" (in 
// debug mode only) generated by AppWizard in every .cpp file.
#ifdef   _DEBUG
#undef   DEBUG_NEW
#define  DEBUG_NEW   ::new(THIS_FILE, __LINE__)
#else
#define  new         ::new(THIS_FILE, __LINE__)
#endif

#define  delete      ::delete