How to use Application Verifier to find memory leaks
Posted
by Patrick
on Stack Overflow
See other posts from Stack Overflow
or by Patrick
Published on 2010-06-02T07:52:37Z
Indexed on
2010/06/02
7:53 UTC
Read the original article
Hit count: 931
I want to find memory leaks in my application using standard utilities. Previously I used my own memory allocator, but other people (yes, you Neil) suggested to use Microsoft's Application Verifier, but I can't seem to get it to report my leaks. I have the following simple application:
#include <iostream>
#include <conio.h>
class X
{
public:
X::X() : m_value(123) {}
private:
int m_value;
};
void main()
{
X *p1 = 0;
X *p2 = 0;
X *p3 = 0;
p1 = new X();
p2 = new X();
p3 = new X();
delete p1;
delete p3;
}
This test clearly contains a memory leak: p2 is new'd but not deleted.
I build the executable using the following command lines:
cl /c /EHsc /Zi /Od /MDd test.cpp
link /debug test.obj
I downloaded Application Verifier (4.0.0665) and enabled all checks.
If I now run my test application I can see a log of it in Application Verifier, but I don't see the memory leak.
Questions:
- Why doesn't Application Verifier report a leak?
- Or isn't Application Verifier really intended to find leaks?
- If it isn't which other tools are available to clearly report leaks at the end of the application (i.e. not by taking regular snapshots and comparing them since this is not possible in an application taking 1GB or more), including the call stack of the place of allocation (so not the simple leak reporting at the end of the CRT)
If I don't find a decent utility, I still have to rely on my own memory manager (which does it perfectly).
© Stack Overflow or respective owner