views:

1296

answers:

2

Hi, I'm trying to use the CRT memory leak detection but I keep getting the following message in Microsoft Visual Studio: "Detected memory leaks - skipping object dump." I can never get the it to actually do and object dump.

I followed the directions in the Microsoft article on Memory Leak Detection (http://msdn.microsoft.com/en-us/library/e5ewb1h3(VS.80).aspx) with no luck.

In my stdafx.h I have (rebuilt the entire project):

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

In the entry point of my application I have:

_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

I'm also hoping that it will display the file name and line number in the Microsoft advertised format:

Detected memory leaks!
Dumping objects ->
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18} 
normal block at 0x00780E80, 64 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.

While I've NEVER been able to even get an object dump, but I've noticed that other people say they see something along these lines (even with _CRTDBG_MAP_ALLOC defined):

Detected memory leaks!
Dumping objects ->
{18} normal block at 0x00780E80, 64 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.

I don't really want to spend time overriding the new and delete operators, so I was hoping that the CRT debugging would help me. If this doesn't work out I might end up overriding the new and delete operators, but I really want to get the allocation information with a file name and line number (crosses fingers).

Thanks, Kiril

+1  A: 

I don't have it here on my machine, but when you instal MSVC you have the option of installing (most of the) source code for the C run-time library (i.e. for MSVCRTxx.xxx). If you look in that source code for "skipping object dump" then you might be able to work out why the object dump is being skipped.

ChrisW
OK, I'll try that, thanks for the info :).
Lirik
Did you got the answer Lirik. Can you please share it with us!
Devil Jin
A: 

The reason file name and line are printed is because the allocation was done using a new macro that passes __FILE__ and __LINE__. If you don't want to touch new, you won't be passing __FILE__ and __LINE__ to the CRT and it won't be able to print that. There's no big magic involved here, really.

MSalters