您当前的位置: 首页 > 热点 > > 内容页

【Visual Leak Detector】配置项 AggregateDuplicates

来源:博客园 2023-03-27 21:24:12

说明

使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 AggregateDuplicates 的使用方法。

目录

1. 配置文件使用说明

在程序中通过 #include "vld.h"的方式检测内存泄漏时,VLD 首先会尝试在程序的生成目录下读取 vld.ini文件,若未读取成功,则会尝试在 VLD 的安装目录下读取 vld.ini文件,若仍未读取成功,则会使用内置的默认配置,内置的默认配置如果不动源码是无法更改的,因此通过修改相应目录下的 vld.ini文件来定制 VLD 功能是最好的选择。当配置参数等号右边为空,或者给配置了不合法值时,在使用过程中会被程序重置到默认值。


(资料图片)

2. 设置是否显示重复的泄漏块

参数名AggregateDuplicates

有效赋值yesno

默认值no

功能说明:为 yes时将合并显示具有相同大小和相同调用堆栈的泄漏内存块,只显示首个泄漏内存块的详细信息,并显示其重复的次数;为 no时则每次泄漏都会单独显示。

2.1 测试代码

#include #include "vld.h"void testFun(int i){    int *ptr = new int(i);    printf("ptr = %08x, *ptr = %08x.\n", ptr, *ptr);}int main(int argc, char *argv[]){    QCoreApplication a(argc, argv);    for (int i = 1; i < 3; i++)    {        testFun(i);    }    return a.exec();}

测试环境:QT 5.9.2MSVC 2015 32bitDebug模式,VLD 版本为 2.5.1,VLD 配置文件只对该参数做修改,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 AggregateDuplicates = no 时的输出

标准输出窗显示:

ptr = 007f7c98, *ptr = 00000001.ptr = 007f8058, *ptr = 00000002.

VLD 输出报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.iniVisual Leak Detector Version 2.5.1 installed.WARNING: Visual Leak Detector detected memory leaks!---------- Block 1 at 0x007F7C98: 4 bytes ----------  Leak Hash: 0xF253A4C4, Count: 1, Total 4 bytes  Call Stack (TID 30620):    ucrtbased.dll!malloc()    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (16): testVLD.exe!main() + 0x9 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 0x007F8058: 4 bytes ----------  Leak Hash: 0xF253A4C4, Count: 1, Total 4 bytes  Call Stack (TID 30620):    ucrtbased.dll!malloc()    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (16): testVLD.exe!main() + 0x9 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.3 AggregateDuplicates = yes 时的输出

标准输出窗显示:

ptr = 00a673d0, *ptr = 00000001.ptr = 00a67400, *ptr = 00000002.

VLD 输出报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.iniVisual Leak Detector Version 2.5.1 installed.    Aggregating duplicate leaks.WARNING: Visual Leak Detector detected memory leaks!---------- Block 1 at 0x00A673D0: 4 bytes ----------  Leak Hash: 0xF253A4C4, Count: 2, Total 8 bytes  Call Stack:    ucrtbased.dll!malloc()    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x7 bytes    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (16): testVLD.exe!main() + 0x9 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                                                  ........ ........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 输出结果对比

上一篇 下一篇
x
推荐阅读 更多
【Visual Leak Detector】配置项 AggregateDuplicates

使用VLD内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍VLD配置文件中配置项AggregateDuplicates的使用方法。

2023-03-27
全球新动态:相约星期二

1、《相约星期二》是美国作家米奇·阿尔博姆创作的自传式长篇纪实小说。该故事真实地讲述了作者的恩师莫里·施瓦茨教授在辞

2023-03-27
2023保亿置业品牌暨观雲产品发布会圆满落幕 环球快播报

2023保亿置业品牌暨观雲产品发布会于3月25日在杭州正式启幕。(观雲产品发布会宣传示意图,企业供图,央广网发)“何为产

2023-03-27
联合丽格杨大平教授浅谈现代审美——假体隆胸“恰到好处”的美|当前热讯

俗话说得好人靠衣装,佛靠金装,现代社会包装对每一个人都很重要,好的形象可以增加一个人的自信,对个人的生活、工作和社会都起着至关重要

2023-03-27
原奶收购价走低 酸奶零售价缘何坚挺

原奶(即生鲜乳)收购价格持续走低。农业农村部近日发布的2023年3月第3周价格数据显示,内蒙古、河北等10个主产省份生鲜乳平均价格3 99元 公斤

2023-03-27
港股异动|建滔积层板(01888)绩后跌超4% 全年营收减少22% 纯利同比下滑近72%

智通财经APP获悉,建滔积层板(01888)午间发布业绩,绩后跌超4%,截至发稿,跌4 18%,报9 17港元,成交额2

2023-03-27
益生股份:公司父母代鸡苗和商品代鸡苗产量较2019年都有提升

每经AI快讯,有投资者在投资者互动平台提问:董秘您好,公司于2019年的那波鸡周期可谓取得了相当大的成功,请问从公司角度来看,今年的景气度

2023-03-27
圆通查快递单号查询查100_圆通快递100单号查询快递查询

1、固乔快递批量查询助手。2、可以批量查询圆通的快递单号。本文到此分享完毕,希望对大家有所帮助。

2023-03-27
太极股份3月27日盘中跌幅达5% 天天快讯

以下是太极股份在北京时间3月27日10:23分盘口异动快照:3月27日,太极股份盘中跌幅达5%,截至10点23分,报40 88元,成交8 70亿元,换手率3 57%

2023-03-27
茂业商业盘中异动 股价振幅达7.88% 上涨6.25%

2023年03月27日临近09时45分,茂业商业(600828)出现异动,股价大幅拉升6 25%。截至发稿,该股报3 9元 股,成交量8 678万手,换手率0

2023-03-27