0

I enabled heap debugging to try and debug some memory leak errors. I do so by including the following:

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

together with the call to _CrtDumpMemoryLeaks() in a function of interest.

Then I also edit the Project Property configuration to set Debugging type to 'Native Only' and add preprocessor definition '_DEBUG' and C/C++ code generation run time library /MDd. I find that no matter where I put the _CrtDumpMemoryLeaks() function call, it dumps memory leak output as follows.

Detected memory leaks!
Dumping objects ->
{2606} normal block at 0x000000003D3A5370, 32 bytes long.
 Data: <VAR1> 54 48 45 52 4D 41 4C 5F 43 4F 4E 44 55 43 54 49 
{2605} normal block at 0x000000003D3A52E0, 32 bytes long.
 Data: <VAR2> 52 4F 43 4B 5F 48 45 41 54 5F 43 41 50 41 43 49 
{2604} normal block at 0x000000003D3A5250, 32 bytes long.
 Data: <VAR3> 45 51 55 49 4C 49 42 52 41 54 49 4F 4E 5F 52 45 
{2603} normal block at 0x000000003D3A51C0, 32 bytes long.
 Data: <VAR4> 4D 41 58 5F 57 41 54 45 52 5F 43 41 50 49 4C 4C 
{2602} normal block at 0x000000003D3A5130, 32 bytes long.
 Data: <VAR5> 4D 41 58 5F 47 41 53 5F 43 41 50 49 4C 4C 41 52 
{2601} normal block at 0x000000003D3A50A0, 32 bytes long.
 Data: <VAR6> 57 41 54 45 52 5F 43 4F 4D 50 52 45 53 53 49 42 
{2600} normal block at 0x000000003D3A5000, 48 bytes long.

What might this mean? Does it mean that if there was a dump output at the point of the call, then the error/leak actually occurs before that? Can we conclude that for sure? If not, it doesn't seem to be a really useful utility. Any advise/help on how to use it correctly or with regards to interpretation is appreciated. Thanks!

1 Answer 1

1

Assume that you have following pairs:

int *x = new int[5];
int *y = new int[7];

delete[] y;
_CrtDumpMemoryLeaks();
delete[] x;

Regardless you delete x later dump will include x as non freed. Actually standard MS technique required high skills of memory management understanding. To simplify your life my recomendation is Visual Leak Detector - easy to embed to your project and easily locate errors (and it is free).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks.. I will give that a try. Appreciate your response!
It seems like that is only valid for 2008/2010. Do you know any options for 2005? Never mind, it looks like it does support 2005.. will give it a shot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.