使用Visual Leak Detector帮助检测使用VS时的内存泄漏

1.在 http://vld.codeplex.com/ 下载安装包

VC6使用vld-1.9的版本,使用高版本可能信息有误。

2.安装vld-2.4rc2-setup.exe,如安装在 D:\Program Files (x86)\Visual Leak Detector

3.在工程属性中配置:

c/c++ -> General -> Additional Include Directories = C:\Program Files (x86)\Visual Leak Detector\include

Linker -> General -> Additional Library Directories = C:\Program Files (x86)\Visual Leak Detector\lib\Win32

4.在 在stdafx.h中增加:

#include"vld.h"

5.把D:/Program Files/Visual Leak Detector/bin/Win32下面的两个DLL
即 dbghelp.dll和vld.dll拷贝到 要调试的exe的目录,即Debug目录下。有时候拷贝vld.dl会使程序无法运行,拷贝dbghelp.dll即可。

6.运行程序,当程序退出时,会在输出窗口看到相关信息。如:

ARNING: Visual Leak Detector detected memory leaks!
---------- Block 88 at 0x060209B0: 48 bytes ----------
Leak Hash: 0xD7638A9E, Count: 1, Total 48 bytes
Call Stack (TID 5908):
f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c (159): MSVCR110D.dll!_malloc_dbg
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxmem.cpp (379): mfc110ud.dll!operator new + 0x18 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxmem.cpp (57): mfc110ud.dll!operator new + 0x13 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp (479): mfc110ud.dll!CWnd::FilterToolTipMessage + 0x11 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp (374): mfc110ud.dll!CWnd::_FilterToolTipMessage
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp (1165): mfc110ud.dll!CWnd::PreTranslateMessage + 0x12 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\barcore.cpp (367): mfc110ud.dll!CControlBar::PreTranslateMessage + 0xC bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp (3368): mfc110ud.dll!CWnd::WalkPreTranslateTree + 0x16 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (233): mfc110ud.dll!AfxInternalPreTranslateMessage + 0x12 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (777): mfc110ud.dll!CWinThread::PreTranslateMessage + 0x9 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (252): mfc110ud.dll!AfxPreTranslateMessage + 0x13 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (178): mfc110ud.dll!AfxInternalPumpMessage + 0x18 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (900): mfc110ud.dll!CWinThread::PumpMessage
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (629): mfc110ud.dll!CWinThread::Run + 0xF bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp (780): mfc110ud.dll!CWinApp::Run
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winmain.cpp (47): mfc110ud.dll!AfxWinMain + 0xF bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appmodul.cpp (26): ScanIDR.exe!wWinMain
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (528): ScanIDR.exe!__tmainCRTStartup + 0x15 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ScanIDR.exe!wWinMainCRTStartup
0x7560336A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77139882 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x77139855 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
2C 00 00 00 00 00 00 00 4C 09 0B 00 22 E1 00 00 ,....... L..."...
17 00 00 00 00 00 00 00 2F 00 00 00 18 00 00 00 ........ /.......
00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 ........ ........


---------- Block 572 at 0x02F2A008: 9220 bytes ----------
Leak Hash: 0x230B62AD, Count: 1, Total 9220 bytes
Call Stack (TID 5908):
HINT: The following call stack may be incomplete. Setting "StackWalkMethod"
in the vld.ini file to "safe" instead of "fast" may result in a more
complete stack trace.
0x752E9CEE (File and line number not available): msvcrt.dll!malloc
0x623AFF96 (File and line number not available): MFC42u.DLL!Ordinal823 + 0x15 bytes
0x623B0321 (File and line number not available): MFC42u.DLL!Ordinal2099 + 0x1F bytes
0x623B0722 (File and line number not available): MFC42u.DLL!Ordinal4155 + 0x7E bytes
0x623B03CE (File and line number not available): MFC42u.DLL!Ordinal1578 + 0x34 bytes
0x623B05A3 (File and line number not available): MFC42u.DLL!Ordinal538 + 0x36 bytes
0x0026627B (File and line number not available): Ism.dll!PIsm::SaveDIBW + 0x7B bytes
Data:
00 00 00 00 9C A0 F2 02 2F 00 00 00 40 00 00 00 ........ /...@...
43 00 3A 00 5C 00 55 00 73 00 65 00 72 00 73 00 C.:.\.U. s.e.r.s.
5C 00 50 00 75 00 62 00 6C 00 69 00 63 00 5C 00 \.P.u.b. l.i.c.\.
50 00 69 00 63 00 74 00 75 00 72 00 65 00 73 00 P.i.c.t. u.r.e.s.
5C 00 74 00 65 00 73 00 74 00 49 00 6D 00 61 00 \.t.e.s. t.I.m.a.
67 00 65 00 5F 00 6E 00 73 00 31 00 32 00 33 00 g.e._.n. s.1.2.3.
34 00 5F 00 30 00 2E 00 62 00 6D 00 70 00 00 00 4._.0... b.m.p...
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 2C A1 F2 02 2F 00 00 00 40 00 00 00 ....,... /...@...
43 00 3A 00 5C 00 55 00 73 00 65 00 72 00 73 00 C.:.\.U. s.e.r.s.
5C 00 50 00 75 00 62 00 6C 00 69 00 63 00 5C 00 \.P.u.b. l.i.c.\.
50 00 69 00 63 00 74 00 75 00 72 00 65 00 73 00 P.i.c.t. u.r.e.s.
5C 00 74 00 65 00 73 00 74 00 49 00 6D 00 61 00 \.t.e.s. t.I.m.a.
67 00 65 00 5F 00 6E 00 73 00 31 00 32 00 33 00 g.e._.n. s.1.2.3.
34 00 5F 00 30 00 2E 00 62 00 6D 00 70 00 00 00 4._.0... b.m.p...





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值