100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 内存泄漏检查工具 Visual Leak Detector(VLD)

内存泄漏检查工具 Visual Leak Detector(VLD)

时间:2018-09-21 12:25:54

相关推荐

内存泄漏检查工具 Visual Leak Detector(VLD)

简介

Windows Leaks Detector is a tool for easy detection of memory leaks in any Windows application. Main features:

No modifications in source code. Actually the code is not required.Works for any Windows application written in any language.Attaching to any running process.Especially effective for applications working in “cyclic” patterns.Aggregation of memory leaks by call stack.

下载安装

下载地址:https://kinddragon.github.io/vld/。

安装一路Next即可,其中注意一点:勾选Add VLD directory to your environmental pathAdd VLD diretory to VS -VS (我的是VS)。

使用

使用VLD只需要引用相关头文件即可,#include <vld.h>

下面是一个使用VLD进行内存泄漏检查的例子:

有内存泄漏

#include <vld.h>int main(){auto* pData1 = new int;auto* pData2 = new int;return 0;}

直接在VisualStudio中运行(开始调试[F5]),输出窗口中输入如下信息:

WARNING: Visual Leak Detector detected memory leaks!---------- Block 2 at 0x00C57620: 4 bytes ----------Leak Hash: 0xB17261AF, Count: 1, Total 4 bytesCall Stack (TID 1352):ucrtbased.dll!malloc()f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): TestVLD.exe!operator new() + 0x9 bytesc:\users\xupeng\desktop\testvld\testvld\main.cpp (6): TestVLD.exe!main() + 0x7 bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (64): TestVLD.exe!invoke_main() + 0x1B bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (255): TestVLD.exe!__scrt_common_main_seh() + 0x5 bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (300): TestVLD.exe!__scrt_common_main()f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): TestVLD.exe!mainCRTStartup()KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytesntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytesntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytesData:CD CD CD CD........ ........---------- Block 1 at 0x00C576E0: 4 bytes ----------Leak Hash: 0x8C97F628, Count: 1, Total 4 bytesCall Stack (TID 1352):ucrtbased.dll!malloc()f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): TestVLD.exe!operator new() + 0x9 bytesc:\users\xupeng\desktop\testvld\testvld\main.cpp (5): TestVLD.exe!main() + 0x7 bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (64): TestVLD.exe!invoke_main() + 0x1B bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (255): TestVLD.exe!__scrt_common_main_seh() + 0x5 bytesf:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (300): TestVLD.exe!__scrt_common_main()f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): TestVLD.exe!mainCRTStartup()KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytesntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytesntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytesData:CD CD CD CD........ ........Visual Leak Detector detected 2 memory leaks (80 bytes).Largest number used: 80 bytes.Total allocations: 80 bytes.Visual Leak Detector is now exiting.

Visual Leak Detector检测到两处内存泄漏,相关的信息在Block 1Block 2中。

另外在输出窗口,点击main.cpp所在行,可以直接在代码中定位到内存泄漏相关代码所在行:

无内存泄漏

如果没有内存泄漏,运行结果如下:

#include <vld.h>int main(){auto* pData1 = new int;auto* pData2 = new int;delete pData1;delete pData2;return 0;}

No memory leaks detected.Visual Leak Detector is now exiting.

其他注意事项

1 如果有include"stdafx.h",则include <vld.h>放在其后,否则放在最前面

2VLD只在Debug版本有效

3 如果想将产生的日志保存到文件中,需要将vld.iniVLD安装目录下)复制到可执行文件目录下,然后作如下修改:

ReportFile =.\memory_leak_report.txt

ReportTo = both

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。