Visual Leak Detector -- VLD内存泄漏检测工具
https://kinddragon.github.io/vld/
https://github.com/KindDragon/vld
https://github.com/KindDragon/vld/releases -- 安装包下载
https://www.cnblogs.com/starfire86/p/5594707.html -- 使用说明
https://blog.csdn.net/chaipp0607/article/details/79182471 -- 内存泄漏工具Visual Leak Detector2.5.1安装与使用
注意事项:
1、源码修改\vld-2.5.1\src\utility.cpp,第721行开始,把原来的wcstombs_s函数替换为WideCharToMultiByte。
因为wcstombs_s不支持中文字符,需要设置Locale参数,setlocale(LC_ALL,"chs");用起来啰嗦还容易出错,故而替换之。
const size_t MAXMESSAGELENGTH = 5119;
size_t count = 0;
CHAR messagea [MAXMESSAGELENGTH + 1];
//firecat add
// wcstombs_s requires locale to be already set up correctly, but it might not be correct on vld init step. So use WideCharToMultiByte instead
//把Unicode文本转换为ANSI
count = WideCharToMultiByte(CP_ACP, 0, messagew, -1, NULL, 0, NULL, NULL);
memset(&messagea, 0, MAXMESSAGELENGTH + 1);
WideCharToMultiByte(CP_ACP, 0, messagew, -1, messagea, count, NULL, NULL);
/*
if (wcstombs_s(&count, messagea, MAXMESSAGELENGTH + 1, messagew, _TRUNCATE) != 0) {
// Failed to convert the Unicode message to ASCII.
assert(FALSE);
return;
}*/
messagea[MAXMESSAGELENGTH] = '\0';
2、发布程序时,应该使用官方源码包自带的dbghelp.dll,路径是\vld-2.5.1\setup\dbghelp\x86和x64文件夹。
不要用C:\Windows\SysWOW64或System32里面的。
3、断点调试程序时,把文件vld.ini放在和.vcxproj工程文件一起的路径下。
发布程序时,把文件vld.ini放在和应用程序exe文件一起的路径下。
4、如何在Release版本下使用VLD?
请参考https://www.jianshu.com/p/1fb05cfdc76d
另外,打开安装路径下的vld.ini文件,将ReportTo设置为both,为了在非bebug下也能看到检测结果
; Sets the report file destination, if reporting to file is enabled. A relative
; path may be specified and is considered relative to the process' working
; directory.
;
; Valid Values: Any valid path and filename.
; Default: .\memory_leak_report.txt
;
ReportFile = .\memory_leak_report.txt
; Sets the report destination to either a file, the debugger, or both. If
; reporting to file is enabled, the report is sent to the file specified by the
; ReportFile option.
;
; Valid Values: debugger, file, both
; Default: debugger
;
ReportTo = both