views:

227

answers:

5

I already know that I can trace memory leaks in my code with mtrace and valgrind on Linux, both of which are unavailable for Windows. Which Windows program would you recommend to trace memory leaks?

I'm an Eclipse user and I've been working with C for a month or two now, so I prefer a user-friendly solution over something more advanced.

+1  A: 

See Purify and possibly Insecure++

Mustapha Isyaku-Rabiu
+1  A: 

You can use _CrtDumpMemoryLeaks. I suppose it is similar to mtrace.

More info: http://www.codeguru.com/forum/showthread.php?t=312742

Moron
A: 

You can hook up e.g. visual leak detector as described here: http://www.codeproject.com/KB/applications/visualleakdetector.aspx

Another way would be to do count the amount of memory used before and after a specific action. Like described here: msdn.microsoft.com/en-us/library/aa293901%28VS.60%29.aspx Something like this can easily added to e.g. automatic unit tests.

Fabian
A: 

There is a common sense way of doing this, in the lines of C, for every pair of malloc there is a free, if there isn't there's a leak, likewise the same for the GlobalAlloc, VirtualAlloc, HeapAlloc, LocalAlloc, VirtualAllocEx...there's an associated ...Free pair with them, for example running a HeapAlloc on variable 'foo' for example, and there is no HeapFree for 'foo', that is a leak...

Hope this helps, Best regards, Tom.

tommieb75
It's more complicated than counting the number of `malloc` and `free` calls in my code because I do these calls in loops.
Pieter
You can create wrappers for `malloc` and `free` that count allocations and deallocations, if you prefer to do things manually. This approach would simplify tracking them and get around the loop situation.
jgottula
+3  A: 

Application Verifier will do this quite well, http://msdn.microsoft.com/en-us/library/ms220948.aspx

Paul Betts
+1. Good suggestion.
Moron
I'm quite confused by Application Verifier, given my limited knowledge of C. mtrace could say I did x amount of mallocs and x amount of frees, but Application Verifier seems to do things that are way too advanced for me to comprehend.
Pieter
AppVerifier tries to simulate your app running under worst-case conditions, then breaks into the debugger whenever anything goes wrong. One of the things that it does catch is leaks, and it will automatically record who did the allocation
Paul Betts
Basically, all you do is from the UI, add your EXE to the list, and mark which tests you want it to run. From then on, AppVerifier will always be applied to your EXE until you disable it
Paul Betts