Free Application to check Memory Leaks in Windows

2020-02-22 02:42发布

问题:

I have been assigned to check memory leak for an API by my boss. The Application is created in C & C++. So there is a possibility that memory is allocated using malloc & new. I want to check the memory leak in Visual Studio 2010 in debugger mode in 64 bit Windows 7. The problem with task manager is that it is not showing stable readings (memory increasing & decreasing by small amounts). Also the difference is small before & after the API is run. So i cannot defitely say that x amount of memory is leaking per cycle.

I have searched on the internet & found that linux has a great tool for this. However I want a reliable tool for my requirements (Windows 7). I have come across these:

http://winleak.sourceforge.net/

http://sourceforge.net/projects/duma/?source=recommended

As mentioned over here:

check Memory leaks in windows

the tool

http://technet.microsoft.com/en-us/library/bb457063.aspx

is not useful for my requirements. It would be very helpful of you guys if you could please suggest a good tool, as the customer who is requesting this is very important for our company. Thank You!

回答1:

I suggest using visual leak detector as it have served me well several times. You may also try to use valgrind for windows (although I had little success on doing that).Dr. Memory also helped me a few times.

EDIT: also have a look here.



回答2:

The CRT library has its own memory leak detection mechanism. The output is not as detailed as what Visual Leak Detector gives you, but it is a lot faster than VLD (which easily runs for dozens of minutes after the program exits).

To enable CRT memory leak detection place the following at the beginning of stdafx.h (or somewhere else suitable):

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

Add the following right before the program's exit point(s):

_CrtDumpMemoryLeaks();

When _CrtDumpMemoryLeaks() is called it prints all leaked memory it can find to the output window.

More information on MSDN.

Note: When I used this I only got the less detailed output without line numbers although I had defined _CRTDBG_MAP_ALLOC right at the beginning of stdafx.h.