Can't detect memory leaks properly.

  • Thread starter Peter Strøiman
  • Start date
P

Peter Strøiman

Hi.

I have a project that leaks :(
I tried using the _crtDumpMemoryLeaks function, and I get the memory leaks
written to the output window, but it doesn't show the correct source file.
Instead it shows the following:
---
Detected memory leaks!
Dumping objects ->
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\crtdbg.h(689)
: {53} normal block at 0x00FD28C0, 112 bytes long.
Data: < G G G G > 94 47 08 10 98 47 08 10 9C 47 08 10 A0 47 08 10
--
And that isn't really very helpful.

The objects that leaks are COM objects implemented using ATL ( It's a
VC++6.0 project that has been loadied into VS2003 - but the code is still
pretty much the same ).
The objects that leak are allocated using the CComObject< T
::CreateInstance function.

I have the following specification in my stdafx.h file

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

I have included malloc.h before crtdbg.h because otherwise the compiler
fails when I have atlbase.h included after crtdbg.h
I have also tried this

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

With the same result.

Can anybody help me to get the correct source code line get displayed in my
debug output?

Thanks in advance,
Peter Strøiman
 
L

Leon Finker

Check atl7+: atldbgmem.h
#include <windows.h>
#include <atldbgmem.h>
#include <atlbase.h>

At the end call: AtlDumpMemoryLeaks();

This tracks: malloc/new/HeapAlloc/VirtualAlloc

For VirtualAlloc it only reports "Memory operation".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top