概述
原创文章,转载请注明出处
目录
-
-
- 目录
- Visual Leak DetectorVLD
- 调试过程
-
Visual Leak Detector(VLD)
Visual Leak Detector(VLD)是一款用于VC的免费开源的内存检测工具,通过内存检测生成相应的报告。
报告内容包括:发生内存泄漏的文件和行号;内存泄漏点的调用堆栈;内存泄漏的完整数据等。
调试过程
环境:VS2015 , vld2.3
vld下载地址:http://vld.codeplex.com/
编译版本安装步骤如下:
- 将vld安装的bin目录下的dbghelp.dll,Microsoft.DTfW.DHL.manifest,vld_x86.dll拷贝到运行的工程目录下(或是添加到环境变量),否则会出现“计算机丢失dbghelp.dll ”和“应用程序无法正常启动(0xc0150002)”的问题;
- 在需要检测内存泄漏的代码文件里#include “vld.h”即可。
源文件安装:
直接下载vld的源程序,将对应的.h文件拷贝到VS的include目录下;将.lid文件拷贝到VS的lib目录下。
可以在安装好的vld目录下编辑vld.ini文件,修改ReportTo = both可以将内存泄漏的报告打印在文件中。
测试用例:
#include "vld.h"
int main() {
int* p_int = new int(1234);
char* p_char = new char('a');
return 1;
}
在Debug模式下运行,内存泄漏报告
Visual Leak Detector Version 2.3 installed.
Outputting the report to the debugger and to E:wzcGittestleaktestleakmemory_leak_report.txt
WARNING: Visual Leak Detector detected memory leaks!
———- Block 59 at 0x003754D0: 40 bytes ———-
Call Stack:
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (359): testleak.exe!heap_alloc_dbg_internal + 0x12 bytes
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (450): testleak.exe!heap_alloc_dbg + 0x15 bytes
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (491): testleak.exe!_malloc_dbg + 0x15 bytes
d:thminkernelcrtsucrtsrcappcrtheapmalloc.cpp (18): testleak.exe!malloc + 0xF bytes
f:ddvctoolscrtvcstartupsrcheapnew_scalar.cpp (19): testleak.exe!operator new + 0x9 bytes
e:wzcgittestleaktestleaktest.cpp (15): testleak.exe!main + 0x7 bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (74): testleak.exe!invoke_main + 0x1B bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (264): testleak.exe!__scrt_common_main_seh + 0x5 bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (309): testleak.exe!__scrt_common_main
f:ddvctoolscrtvcstartupsrcstartupexe_main.cpp (17): testleak.exe!mainCRTStartup
0x77F1EE6C (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77DC399B (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xEF bytes
0x77DC396E (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xC2 bytes
Data:
00 00 00 00 00 55 37 00 00 00 00 00 00 00 00 00 …..U7. ……..
01 00 00 00 04 00 00 00 3B 00 00 00 FD FD FD FD …….. ;…….
D2 04 00 00 FD FD FD FD …….. ……..
———- Block 60 at 0x00375500: 37 bytes ———-
Call Stack:
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (359): testleak.exe!heap_alloc_dbg_internal + 0x12 bytes
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (450): testleak.exe!heap_alloc_dbg + 0x15 bytes
d:thminkernelcrtsucrtsrcappcrtheapdebug_heap.cpp (491): testleak.exe!_malloc_dbg + 0x15 bytes
d:thminkernelcrtsucrtsrcappcrtheapmalloc.cpp (18): testleak.exe!malloc + 0xF bytes
f:ddvctoolscrtvcstartupsrcheapnew_scalar.cpp (19): testleak.exe!operator new + 0x9 bytes
e:wzcgittestleaktestleaktest.cpp (16): testleak.exe!main + 0x7 bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (74): testleak.exe!invoke_main + 0x1B bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (264): testleak.exe!__scrt_common_main_seh + 0x5 bytes
f:ddvctoolscrtvcstartupsrcstartupexe_common.inl (309): testleak.exe!__scrt_common_main
f:ddvctoolscrtvcstartupsrcstartupexe_main.cpp (17): testleak.exe!mainCRTStartup
0x77F1EE6C (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77DC399B (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xEF bytes
0x77DC396E (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xC2 bytes
Data:
D0 54 37 00 00 00 00 00 00 00 00 00 00 00 00 00 .T7….. ……..
01 00 00 00 01 00 00 00 3C 00 00 00 FD FD FD FD …….. <…….
61 FD FD FD FD a……. ……..
Visual Leak Detector detected 2 memory leaks (77 bytes).
Largest number used: 11554 bytes.
Total allocations: 16495 bytes.
Visual Leak Detector is now exiting.
最后
以上就是正直牛排为你收集整理的内存泄漏调试(2)——VLD的全部内容,希望文章能够帮你解决内存泄漏调试(2)——VLD所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复