C++ 檢測內存泄露工具 -- Windows平臺

平臺:Windows7 64bit,編譯器G++(mingw)windows

工具:Dr Memory,項目主頁:https://code.google.com/p/drmemory/ (可能要FQ,可能會很慢,因此,能夠直接按照下面官方主頁給出的連接下載,我也放了一份Windows版的在百度網盤,http://pan.baidu.com/s/1qWv2tZm,這個應該確定能夠下載)wordpress

The latest versions can be directly accessed here:工具

2014-08-30日摘錄於https://code.google.com/p/drmemory/wiki/Downloads?tm=2測試

用法相似於Linux下的Valgrind,很是簡單google

 測試代碼:spa

#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中止工做")debug

執行drmemory test.exe調試

這樣應該就會生成一個報告,能夠看到Error #1: LEAK 100 direct bytes 0x00c80ea8-0x00c80f0c + 0 indirect bytescode

 

 

關於微軟的App Verifier,http://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx, 按照說明能夠下載其中的debugging tool,安裝成功後,搞了半天也沒學會怎麼用……blog

我是用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/

相關文章
相關標籤/搜索