内存泄露检测工具【VLD v2.2.3】

本文介绍如何在Visual Leak Detector的帮助下,通过一系列步骤来检测并定位C++程序中的内存泄漏问题。包括设置环境、配置编译选项、包含头文件以及如何识别和处理内存泄漏错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载地址:http://vld.codeplex.com/releases/view/82311

注意:这些设置是针对一个工程的,所以要先打开一个progject才可以设置。

完装完成后会提示打开文档,然后会打开一个在线的静态帮助页面,点击Using Visual Leak Detector后有安装帮助,我用的是VC 2010 Express版本(正版的免费编译器可以自己去MS那里下载),不过这个帮助指引写的和我所用的版本有点差异,我写下自己的使用方法:

1)View->Property Manager

2)右键Debug | Win32下的Microsoft.Cpp.Win32.user选Property

3)选VC++ Directories项

4)将VLD目录下的include子文件夹添加到Include Directories里

5)将VLD目录下的lib\win32子文件夹添加到Library Directories里

PS:根据自己的软件选择添加win32还是win64

6)在自己的程序里#include <vld.h>,注意要最后包含这个头文件。

7)如果有泄露会在output窗口显示泄露,这是个例子,只new了一个内存但没有delete:

int main(int argc,char* argv[]){ new int; return 0;}
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x003A2BB0: 4 bytes ----------
  Call Stack:
    d:\practice\cpp\t001\test\test\main.cpp (10): test.exe!main + 0x7 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (555): test.exe!__tmainCRTStartup + 0x19 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (371): test.exe!mainCRTStartup
    0x7C817077 (File and line number not available): kernel32.dll!RegisterWaitForInputIdle + 0x49 bytes
  Data:
    CD CD CD CD                                                  ........ ........



Visual Leak Detector detected 1 memory leak (40 bytes).
Largest number used: 40 bytes.
Total allocations: 40 bytes.
Visual Leak Detector is now exiting.

The program '[3504] test.exe: Native' has exited with code 0 (0x0).

转自:http://hi.baidu.com/pdaliu/item/5b70bfb8948e9bea4fc7fda6



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值