C++ 检测内存泄露工具 -- Windows平台

平台:Windows7 64bit,编译器G++(mingw)

工具:Dr Memory,项目主页:https://code.google.com/p/drmemory/ (可能要FQ,可能会很慢,所以,可以直接按照下面官方主页给出的链接下载,我也放了一份Windows版的在百度网盘,http://pan.baidu.com/s/1qWv2tZm,这个应该肯定可以下载)

The latest versions can be directly accessed here:

2014-08-30日摘录于https://code.google.com/p/drmemory/wiki/Downloads?tm=2

用法类似于Linux下的Valgrind,非常简单

 测试代码:

#include <cstdio>
int main(int argc, const char *argv[])
{
    char *s;
    s = new char[100];
    return 0;
}

用g++编译,g++ test.cpp -o test (貌似必须有-o选项指定输出文件名,用g++ test.cpp会生成a.exe,但是用drmemory会导致显示"a.exe停止工作")

执行drmemory test.exe

这样应该就会生成一个报告,可以看到Error #1: LEAK 100 direct bytes 0x00c80ea8-0x00c80f0c + 0 indirect bytes

 

 

关于微软的App Verifier,http://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx, 按照说明可以下载其中的debugging tool,安装成功后,搞了半天也没学会怎么用……

我是用mingw的工具编译和调试,g++ file.cpp -o file,生成exe,打开App Verifier,添加这个exe,执行gdb file.exe,run的时候确实看到说App Verifier enable了,但是无论是运行过程中还是运行之后都看不到log。很可能是只能和windbg工具一起使用,可能还要用微软的编译器。搜索 “App Verifier 内存泄露”可以得到很多相关文章,比如这篇文章:http://www.zzfjh.com/?p=105 

 

参考:

https://code.google.com/p/drmemory/

http://latedev.wordpress.com/2012/05/19/valgrind-for-windows/

posted @ 2014-08-30 13:03  ttang  阅读(9333)  评论(0编辑  收藏  举报