views:

48

answers:

1

Has anybody personally used

AfxEnableMemoryTracking function provided by MFC

to detect memory leaks. How useful is it?

+3  A: 

Memory tracking is enabled by default in MFC Debug builds. AfxEnableMemoryTracking is mostly used to temporary disable memory tracking in some code fragments, if it is necessary. To use MFC built-in memory leaks detection, ensure that every .cpp file contains the following code after all #include lines:

#ifdef _DEBUG
#define new DEBUG_NEW 
#endif
Alex Farber
Why not just define in a header?
DeadMG
Redefinition of new operator in h-file may cause compilation of many h-files to fail, or undefined behavior of some libraries. This is the reason why new operator is defined locally only for .cpp file.
Alex Farber