1. 安裝DebugDiagx63.exe
2. 運行需要測試的程序UnitTest.exe.
3. 打開DebugDiag1.2, 選擇 ”Native (non-.Net) Memory and Handle Leak” ,然后next.
4. 選中UnitTest.exe進程, next
5. 保持default選擇, next
6. 生成Leak Rules, 保持default選擇, next
7. 保持”Active the rule now”選擇, Finish.
8. ToolsàOptions And Settings
(1) Folders and Search Paths: 添加Symbols文件: SRV*D:\symbol*http://msdl.microsoft.com/download/symbols;D:\xxx-YourProjectPdbFilePath.
Dump文件保存路徑保持不變.
(2) Preferences: 勾選”檢測內存泄露時立即記錄調用棧信息”,當測試時間>15mins時不建議勾選.
9. 運行UnitTest程序,為了產生較多的泄露,可以多運行幾次.
10. Rules選項卡中,右鍵點擊Leak RuleàDump Target Process(es)àCreate Full Userdump(s).從而生成dump文件.位置在E:\Program Files\DebugDiag\Logs\Misc下.
11. Advanced Analysis選項卡, 選中第二個”Memory Pressure Analyzers” (第一個是分析托管的內存). 然后點擊Add Data Files. 加載Misc文件夾下的dump文件, 然后點擊”Start Analysis”按鈕進行分析, 會生成一個html頁面, 在IE中自動打開.
12. 在頁面中搜索,找到 ”Module details for mfc100”, 查詢其 ”operator new”函數的調用棧samples. 可以找到代碼中用到new可能造成的內存泄露之處.
Function |
Source |
Destination |
mfc100!operator new+33 |
|
|
TestCaseAdapter!CTracerouteAdapterFactory::CreateObject+2d |
d:\xxx\tracerouteadapter.cpp @ 39 + 8 |
mfc100!operator new |
TestCases!TracerouteTest::testTracerouteWithWrongHost+153 |
d:\xxx\traceroutetest.cpp @ 67 + 16 |
|