I tried building a test application (basic MFC SDI
application) to try it out.
At the top of Leaktest.h, I have
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
In CLeakTestApp::InitInstance(), I have
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF);
and I have a menu item that malloc's 5555 bytes.
When I quit the program, I get
Detected memory leaks!
Dumping objects ->
{90} normal block at 0x00325118, 5555 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD
CD CD CD CD CD CD
Object dump complete.
Why am I not getting the info I need?
Btw, in my main application, I also tried using the
memory allocation number to break on the leak but the
number changes every time although I'm running it the
same each time, even down to using keyboard rather than
mouse in case different mouse movements cause different
events each time.
Any help would be hugely appreciated.
--- Al.
The MFC header <afx.h> already #includes <crtdbg.h>, and since you're
#defining _CRTDBG_MAP_ALLOC after the latter has been #included, it has no
effect. You'll need to #define _CRTDBG_MAP_ALLOC in your stdafx.h file,
before <afx.h> is #included. You can delete your _CrtSetDbgFlag call, as MFC
already dumps leaks.
--
Doug Harrison
Microsoft MVP - Visual C++