Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

_CRTDBG_MAP_ALLOC doesn't seem to work

473 views
Skip to first unread message

Alistair

unread,
Oct 16, 2003, 8:51:12 AM10/16/03
to
I'm having problems tracking down a meory leak and
thought the best way would be to follow the instructions
in MDSN: "Detecting and Isolating Memory Leaks Using
Microsoft Visual C++" However, I can only get the basic
memory dump, without source file and line number. It's as
if _CRTDBG_MAP_ALLOC is being ignored.

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.

Doug Harrison [MVP]

unread,
Oct 16, 2003, 1:49:29 PM10/16/03
to
Alistair wrote:

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++

0 new messages