【Visual Leak Detector】配置项 ForceIncludeModulesmd
说明
使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 ForceIncludeModules 的使用方法。 同系列文章目录可见 《内存泄漏检测工具》目录
1. 配置文件使用说明
在程序中通过 #include "vld.h" 的方式检测内存泄漏时,VLD 首先会尝试在程序的生成目录下读取 vld.ini 文件,若未读取成功,则会尝试在 VLD 的安装目录下读取 vld.ini 文件,若仍未读取成功,则会使用内置的默认配置,内置的默认配置如果不动源码是无法更改的,因此通过修改相应目录下的 vld.ini 文件来定制 VLD 功能是最好的选择。当配置参数等号右边为空,或者给配置了不合法值时,在使用过程中会被程序重置到默认值。
2. 设置需要检测的第三方模块
参数名:ForceIncludeModules。
有效赋值:包含模块名的列表。
默认值:无。
功能说明:当需要对第三方模块(exe、lib、dll)进行内存泄漏检测,但又没法在这些模块的源码中 #include "vld.h" 时,可以在等号右边列出这些模块的名称,模块之间可使用任意分隔符,甚至不分隔也可以,但为了便于阅读,通常使用空格、; 或 , 来进行分隔。需要注意的是,这个功能开启后程序有崩溃的风险,有时候还会输出错误的内存泄漏报告。
2.1 测试代码
#include <QCoreApplication>
#include "vld.h"
#include "testdll1.h"
#include "testdll2.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TestDll1 aaa;
aaa.testFun(1);
TestDll2 bbb;
bbb.testFun(2);
return a.exec();
}
测试环境:QT 5.9.2,MSVC 2015 32bit,Debug 模式,VLD 版本为 2.5.1,VLD 配置文件只对该参数做修改,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD。其中的 testdll1 与 testdll2 是为了测试而打包的库,两个库里的函数都存在内存泄漏。
2.2 ForceIncludeModules 为空时的输出
标准输出窗显示:
testDLL1 ptr = 00840bc0, *ptr = 00000001.
testDLL2 ptr = 00840b90, *ptr = 00000002.
VLD 输出报告:
Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
No memory leaks detected.
Visual Leak Detector is now exiting.
2.3 ForceIncludeModules = 指定库时的输出
以下 ForceIncludeModules 配置的效果相同:
ForceIncludeModules = testDll1.dll;testDll2.dll // 使用英文分号做分隔符
ForceIncludeModules = testDll1.dll,testDll2.dll // 使用英文逗号做分隔符
ForceIncludeModules = testDll1.dll testDll2.dll // 使用空格做分隔符
ForceIncludeModules = testDll1.dll/testDll2.dll // 使用斜杠做分隔符
ForceIncludeModules = testDll1.dll-testDll2.dll // 使用减号做分隔符
ForceIncludeModules = testDll1.dlltestDll2.dll // 不使用任何分隔符
ForceIncludeModules = testDll1.dllabcdefghtestDll2.dll // 使用字符串abcdefgh做分隔符
ForceIncludeModules = testDll1.dll++++++testDll2.dll // 使用字符串++++++做分隔符
标准输出窗显示:
testDLL1 ptr = 00e070f8, *ptr = 00000001.
testDLL2 ptr = 00e072a8, *ptr = 00000002.
VLD 输出报告:
Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
Forcing inclusion of these modules in leak detection: testdll1.dll;testdll2.dll
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00E070F8: 4 bytes ----------
Leak Hash: 0x8BB01C20, Count: 1, Total 4 bytes
Call Stack (TID 14012):
ucrtbased.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testDll1.dll!operator new() + 0x9 bytes
e:\cworkspace\qt 5.9\qtdemo\testdll1\testdll1.cpp (10): testDll1.dll!TestDll1::testFun() + 0x7 bytes
e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (11): testVLD.exe!main() + 0xB bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
Data:
01 00 00 00 ........ ........
---------- Block 2 at 0x00E072A8: 4 bytes ----------
Leak Hash: 0x08AA1CDB, Count: 1, Total 4 bytes
Call Stack (TID 14012):
ucrtbased.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testDll2.dll!operator new() + 0x9 bytes
e:\cworkspace\qt 5.9\qtdemo\testdll2\testdll2.cpp (10): testDll2.dll!TestDll2::testFun() + 0x7 bytes
e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0xB bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
Data:
02 00 00 00 ........ ........
Visual Leak Detector detected 2 memory leaks (80 bytes).
Largest number used: 80 bytes.
Total allocations: 80 bytes.
Visual Leak Detector is now exiting.
2.4 输出结果对比
- 当
ForceIncludeModules为空时,没有检测出动态库里的内存泄漏。 - 当
ForceIncludeModules指定了库testDll1.dll与testDll2.dll时,成功检测到了动态库里的内存泄漏,并指出了文件和行号等信息。
【Visual Leak Detector】配置项 ForceIncludeModulesmd的更多相关文章
- 使用Visual Leak Detector for Visual C++ 捕捉内存泄露
什么是内存泄漏? 内存泄漏(memory leak),指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况.内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,失去了对该段 ...
- Visual Leak Detector 2.2.3 Visual C++内存检测工具
Visual Leak Detector是一款免费的.健全的.开源的Visual C++内存泄露检测系统.相比Visual C++自带的内存检测机制,Visual Leak Detector可以显 ...
- 使用Visual Leak Detector检测内存泄漏[转]
1.初识Visual Leak Detector 灵活自由是C/C++语言的一大特色,而这也为C/C++程序员出了一个难题.当程序越来越复杂时,内存的管理也会变得越加复杂,稍有不慎就会出现内存问题 ...
- Cocos开发中性能优化工具介绍之Visual Studio内存泄漏检测工具——Visual Leak Detector
那么在Windows下有什么好的内存泄漏检测工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检测功能,我们可以使用第三方工具Visual Leak Detector(以下简 ...
- vld(Visual Leak Detector) 内存泄露检测工具
初识Visual Leak Detector 灵活自由是C/C++语言的一大特色,而这也为C/C++程序员出了一个难题.当程序越来越复 杂时,内存的管理也会变得越加复杂,稍有不慎就会出现内存问题.内存 ...
- Cocos性能优化工具的开发介绍Visual Studio内存泄漏检测工具——Visual Leak Detector
然后,Windows下有什么好的内存泄漏检測工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检測功能.我们能够使用第三方工具Visual Leak Detector(下面简 ...
- VisualStudio 怎么使用Visual Leak Detector
VisualStudio 怎么使用Visual Leak Detector 那么在Windows下有什么好的内存泄漏检测工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检测 ...
- Visual Leak Detector简明使用教程
Visual Leak Detector是一款内存泄漏检测软件,主要的作用就是检测可能或者是存在内存泄露的地方,具体的功能的话,可以百度下,今天主要简单介绍下怎么使用 首先下载Visual Leak ...
- Visual Leak Detector原理剖析
认识VLD VLD(Visual Leak Detector)是一款用于Visual C++的开源内存泄漏检测工具,我们只需要在被检测内存泄漏的工程代码里#include “vld.h”就可以开启内存 ...
- VS2017 编译 Visual Leak Detector + VLD 使用示例
起因 一个Qt5+VS2017的工程,需要进行串口操作,在自动时发现一段时间软件崩溃了,没有保存log,在 debug 的时候发现每运行一次应用占据的内存就多一点,后来意识到是内存泄漏了.这个真是头疼 ...
随机推荐
- python + uiautomator2 常用公共方法封装
前言 由于公司UI自动化框架底层用的是Uiautomator2,所以我就用Uiautomator2搭了一套UI自动化框架,思路其实和Appnium一样的. uiautomator2是一个自动化测试开源 ...
- kafka例子
<dependencies> <dependency> <groupId>org.apache.kafka</groupId> <artifact ...
- 【Linux】Ubuntu随笔
Ubuntu声明环境变量时使用 export JAVA_HOME=/xx/xx/xx,当需要引用时要写成 $JAVA_HOME 所以配置环境变量并声明方法如下: vim ~/.bashrc expor ...
- function | ECOS
用于优化线性或二阶锥的自对偶齐次嵌入内点方法. 不支持 SDP 锥体! [x,y,info,s,z] = ecos(c,G,h,dims,A,b) 求解一对原始和双锥程序 最小化 c'x 服从 Gx ...
- Java 方法详解 与数组
基础阶段: 1.何谓方法 何谓方法?◆System.out.println(),那么它是什么呢?◆Java方法是语句的集合,它们在- -起执行一个功能. ◆方法是解决一类问题的步骤的有序组合 ...
- 了解JAVA基本知识以及一下常用的dos命令
9月5日学习 常用的Dos命令 #盘符切换盘符名称: =>回车#查看当前目录下的所有文件dir#切换目录 cd change directorycd .. =>返回上一级目录#清理屏 ...
- 十大经典排序之桶排序(C++实现)
桶排序 桶排序是计数排序的升级版.它利用了函数的映射关系,高效与否的关键就在于这个映射函数的确定 思路: 根据数据规模,初始化合理桶数 将数列中的数据按照桶的规模进行映射,尽量保证数据被均匀的分布到桶 ...
- kettle连接mysql报Communications link failure
添加2个命名参数 1.autoReconnect=true 2.useSSL=false
- logstash从MySQL导入数据到ES
下载安装 一定要对应ES版本(5.x,6.x,7.x) win下不用安装解压即用 , 解压目录不能带有空格和中文 , 否则会有奇奇怪怪的报错无法运行 win下要给logstash文件夹赋予管理员权限 ...
- Hadoop 从 hdfs 中拷出文件权限不够
问题:使用-get命令从hdfs中拷出文件时,提示权限不够,如下: 分析: 可能有三方面原因: hdfs 中的文件或文件夹 没有读取权限: hdfs 的配置中未允许拷出文件: linux 文件夹没有写 ...