当前位置: 首页 > 网络知识

Qt 使用 Visual Leak Detector(方式二)

时间:2026-01-29 09:26:48

1. 使用前的准备
  参考本人另一篇博客 安装 Visual Leak Detector 下载 vld2.5.1setup.exe 并按步骤安装 VLD。这一种使用方式的特点是,在一台电脑上安装完成后,需在项目 pro 文件中指明库及头文件的路径,然后在 mianpp 文件中 #include "vld.h"。当把项目拷贝到别的电脑上编译运行时,需要确保该电脑已经使用 vld2.5.1setup.exe 安装了 VLD,并更改项目 pro 文件中指明的相关路径。

2. 在 QT 中使用 VLD
  我的 VLD 安装目录为 D:\Program Files (x86)\Visual Leak Detector。

2.1 在项目 .pro 文件中指明路径
  在项目对应的 pro 文件中指明 VLD 的 include 目录和 lib 文件,pro 文件中添加如下代码:

1 win32else 11 } 12 }

2.2 在 mainpp 文件中添加头文件

  在项目的mainpp文件中,添加头文件:

#include "vld.h"

  选择MSVC32bit 或者 MSVC 64bit 编译器,选择Debug模式,编译运行,就可以正常使用了。

2.3 无内存泄漏时的输出报告

  程序运行结束后,若没有检测到内存泄漏,VLD 会输出以下 4 行报告:

1 Visual Leak Detector read settings fr: D:\Program Files (x86)\Visual Leak Detector\vld.ini 2 Visual Leak Detector Version 2.5.1 installed. 3 No memory leaks detected. 4 Visual Leak Detector is now exiting.

2.4 有内存泄漏时的输出报告

  程序运行结束后,若检测到内存泄漏,VLD 会输出以下报告(本例中出现一处内存泄漏):

1 Visual Leak Detector read settings fr: D:\Program Files (x86)\Visual Leak Detector\vld.ini 2 Visual Leak Detector Version 2.5.1 installed. 3 WARNING: Visual Leak Detector detected memory leaks! 4 Block 1 at 0x00000000977910B0: 20 bytes 5 Leak Hash: 0x0A94032F, Count: 1, Total 20 bytes 6 Call Stack (TID 12424): 7 ucrtbased.dll!malloc() 8 f:\dd\vctools\crt\vcstartup\src\heap\new_arraypp (16): testVLD.exe!operator new[]() 9 e:\cworkspace\qt 5.9.0\qtdemo\testvld\mainpp (12): testVLD.exe!main() + 0xA bytes 10 f:\dd\vctools\crt\vcstartup\src\startup\exe_cmon.inl (75): testVLD.exe!invoke_main() 11 f:\dd\vctools\crt\vcstartup\src\startup\exe_cmon.inl (264): testVLD.exe!__scrt_cmon_main_seh() + 0x5 bytes 12 f:\dd\vctools\crt\vcstartup\src\startup\exe_cmon.inl (309): testVLD.exe!__scrt_cmon_main() 13 f:\dd\vctools\crt\vcstartup\src\startup\exe_mainpp (17): testVLD.exe!mainCRTStartup() 14 KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes 15 ntdll.dll!RtlUserThreadStart() + 0x21 bytes 16 Data: 17 CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........ 18 CD CD CD CD ........ ........ 19 20 21 Visual Leak Detector detected 1 memory leak (72 bytes). 22 Largest number used: 72 bytes. 23 Total allocations: 72 bytes. 24 Visual Leak Detector is now exiting.

3. 无法正常使用的可能原因



上一篇:Qt QChart更新chart占用内存持续增大问题的解决
下一篇:ModbusTCP协议简介与编程流程图
Qt VisualLeakDetector
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素