- memory leak
- Posted by Nick Keighley on October 13th, 2006
Hi,
I'm chasing a possible memory leak (it could be my program is just
allocating
a lot of memory) so I'm interested in what memory is allocated aver a
period
of time, say 1/2 an hour.
I tried using _CrtMemCheckpoint (&checkpoint) at the beginning of the
time
period then _CrtMemDumpAllObjectsSince(&checkpoint) at the end. This
didn't seem to do what I wanted. I did this twice then diffed the
result, most
of the two results were identical. I suspect
_CrtMemDumpAllObjectsSince()
is dumping all the allocations not just those since the chekpoint. Is
my
expectation of the behaviour of _CrtMemDumpAllObjectsSince() correct?
Is there any way to find out who allocated the memory. Overide operator
new()?
--
Nick Keighley
- Posted by Michael on October 14th, 2006
In MFC, there's a macro called DEBUG_NEW that's useful. You basically
put code like this in your .cpp file after the includes and before the
actual code
#ifdef DEBUG
#define new DEBUG_NEW
#endif
Then the object dump contains file and line number of allocation.
I'd suggest you try this with one file before going too crazy. Maybe
add a bogus allocation:
int* p = new int;
and make sure it works.
I'm not sure if that's MFC specific (although, now that I look at it,
it's defined in afx.h, so that's a bad sign). There's an example of a
non-MFC version in MSDN under
http://msdn2.microsoft.com/en-us/library/19f56tw3.aspx It looks like
they've used DEBUG_CLIENT_BLOCK instead of DEBUG_NEW as their macro.
(Note: I haven't tried this latter approach.)
Michael
- Memory Leak (Performance/Maintainence) by tn
- Will this do memory leak ? (Development Resources) by DanSteph
- memory leak (Development Resources) by Hilla
- maybe a memory leak (Development Resources) by Torsten Curdt
- Can increase in 'Memory showed in Task Manager' be a memory leak indicator ? (Development Resources) by qazmlp

