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!
Press Windows+R to open the Run dialog; enter "resmon" and click OK. With Resource Monitor open, select the Memory tab. Looking at Physical Memory, start by confirming the correct amount is displayed as installed, to ensure that there isn't a hardware issue.
Using Memory Profilers Memory profilers are tools that can monitor memory usage and help detect memory leaks in an application. Profilers can also help with analyzing how resources are allocated within an application, for example how much memory and CPU time is being used by each method.
The best approach to checking for the existence of a memory leak in your application is by looking at your RAM usage and investigating the total amount of memory been used versus the total amount available. Evidently, it is advisable to obtain snapshots of your memory's heap dump while in a production environment.
The Visual Studio debugger and C Run-time Library (CRT) can help you detect and identify memory leaks.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With