Problem about finding memory leak
-
While running debug mode on an application written by me, the debug would complain that it has memory leak:
Detected memory leaks!
Dumping objects ->
{118957} normal block at 0x04D89230, 22960 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
...Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!
-
While running debug mode on an application written by me, the debug would complain that it has memory leak:
Detected memory leaks!
Dumping objects ->
{118957} normal block at 0x04D89230, 22960 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
...Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!
VS has the ability to help you with that. What you have to do is add the following lines, which should be there by default, to the beginning of every cpp file in your project
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIf you have these lines in your code, then the debugger will give you the file name and line number of where the leaked memory was allocated, making it easier for you to figure out where you forgot to add the delete.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
VS has the ability to help you with that. What you have to do is add the following lines, which should be there by default, to the beginning of every cpp file in your project
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIf you have these lines in your code, then the debugger will give you the file name and line number of where the leaked memory was allocated, making it easier for you to figure out where you forgot to add the delete.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
While running debug mode on an application written by me, the debug would complain that it has memory leak:
Detected memory leaks!
Dumping objects ->
{118957} normal block at 0x04D89230, 22960 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
...Is there any tool to trace the memory usage? It may be hard to find where the error is by simply trace the code( too long to examine X| ) Thanks!
First you have to include the following files in your main .h file (so that you can have access to the following functions anywhere) //For debugging #define CRTDBG_MAP_ALLOC #include #include do them in this order. Now you can use the following function to actually call a memory dump with verbose leak pinpointing. _CrtDumpMemoryLeaks(); a small hint; bookmark the function, and clear your output window before stepping through the function call When the going gets tough... write a computer program to do the thing for you