Finding memory leak 
Author Message
 Finding memory leak

My program has one or more severe memory leaks that I'm trying to find.
Using the article at
http://www.*-*-*.com/
added:

#define _CRTDBG_MAP_ALLOC

#include <stdlib.h>

#include <crtdbg.h>

and the _CrtDumpMemoryLeaks() function to my code

The output is:

Detected memory leaks!

Dumping objects ->

g:\program files\microsoft visual studio .net\vc7\include\crtdbg.h(674) :
{45} normal block at 0x0235EF80, 120 bytes long.

Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00

g:\program files\microsoft visual studio .net\vc7\include\crtdbg.h(674) :
{44} normal block at 0x0235CFF0, 12 bytes long.

Data: <|RD 5 > 7C 52 44 00 0A 00 00 00 80 EF 35 02

Object dump complete.

The program '[2588] myc.exe: Native' has exited with code 0 (0x0).

Why doesn't the log refer to where the leaked memory was allocated in my
program??



Wed, 06 Jul 2005 17:56:16 GMT  
 Finding memory leak

Quote:

> My program has one or more severe memory leaks that I'm trying to
> find. Using the article at
> http://msdn.microsoft.com/library/en-us/dnvc60/html/memleaks.asp I
> have added:

> #define _CRTDBG_MAP_ALLOC

> #include <stdlib.h>

> #include <crtdbg.h>

> and the _CrtDumpMemoryLeaks() function to my code

> The output is:

> Detected memory leaks!

> Dumping objects ->

> g:\program files\microsoft visual studio
> .net\vc7\include\crtdbg.h(674) : {45} normal block at 0x0235EF80, 120
> bytes long.

> Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00

> g:\program files\microsoft visual studio
> .net\vc7\include\crtdbg.h(674) : {44} normal block at 0x0235CFF0, 12
> bytes long.

> Data: <|RD 5 > 7C 52 44 00 0A 00 00 00 80 EF 35 02

> Object dump complete.

> The program '[2588] myc.exe: Native' has exited with code 0 (0x0).

> Why doesn't the log refer to where the leaked memory was allocated in
> my program??

This is a side effect of operator new being inlined.

In order to get the actual line where the allocation
occurred, add these lines after #include <crtdbg.h>:

#if defined _DEBUG
   #define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif

This will cause the preprocessor to replace the
occurances of new, and these substitutions will
have the correct __FILE__ and __LINE__ info.

You'll have to make this change in each file
that includes "crtdbg.h" otherwise you'll simply
get the header allocation info.

Joe



Thu, 07 Jul 2005 02:09:08 GMT  
 Finding memory leak

Quote:

> My program has one or more severe memory leaks that I'm trying to find.
> Using the article at
> http://msdn.microsoft.com/library/en-us/dnvc60/html/memleaks.asp I have
> added:

> #define _CRTDBG_MAP_ALLOC

The simple CRT-implemantation does for example not work with stl... or
other "hidden" memory allocations.

If you want to get the callstack you can use my tool at:
http://www.codeproject.com/useritems/leakfinder.asp

--
Greetings
  Jochen

  Do you need a memory-leak finder ?
  http://www.codeproject.com/useritems/leakfinder.asp



Fri, 08 Jul 2005 14:32:10 GMT  
 Finding memory leak

If the allocation numbers (the ones in {}) remain the same with every run of
your program, you can break in the de{*filter*} when they are allocated.

Try this:

  long lBreakAlloc =44;  // your allocation number from the debug output
_CrtSetBreakAlloc( lBreakAlloc );

The log would show your code line if the allocated object where derived from
CObject.

soeren


Quote:
> My program has one or more severe memory leaks that I'm trying to find.
> Using the article at
> http://www.*-*-*.com/
> added:

> #define _CRTDBG_MAP_ALLOC

> #include <stdlib.h>

> #include <crtdbg.h>

> and the _CrtDumpMemoryLeaks() function to my code

> The output is:

> Detected memory leaks!

> Dumping objects ->

> g:\program files\microsoft visual studio .net\vc7\include\crtdbg.h(674) :
> {45} normal block at 0x0235EF80, 120 bytes long.

> Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00

> g:\program files\microsoft visual studio .net\vc7\include\crtdbg.h(674) :
> {44} normal block at 0x0235CFF0, 12 bytes long.

> Data: <|RD 5 > 7C 52 44 00 0A 00 00 00 80 EF 35 02

> Object dump complete.

> The program '[2588] myc.exe: Native' has exited with code 0 (0x0).

> Why doesn't the log refer to where the leaked memory was allocated in my
> program??



Fri, 08 Jul 2005 21:30:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Finding memory leaks in shared memory pool

2. ANN: Source for finding memory leaks

3. Finding memory leaks at compile time?

4. How to find memory leaks in unix

5. Finding memory leaks !!!

6. finding memory leaks

7. Finding memory leaks

8. FYI: Hard-to-find memory leak

9. ANN: Source for finding memory leaks

10. Finding memory leak

11. Finding memory leaks

12. Trouble finding memory leak

 

 
Powered by phpBB® Forum Software