使用Visual Leak Detector检测内存泄露

本文来自VLD官网文档:

文档源地址:http://vld.codeplex.com/wikipage?title=Using%20Visual%20Leak%20Detector&referringTitle=Documentation

当前最新版本 2.3 http://vld.codeplex.com/releases

使用Visual Leak Detector


本文简单介绍了一下VLD的基本使用方法。

配置方法:


注意!使用VLD之前,必须将VLD的inlcude和library目录添加到VC++项目的include和library搜索目录下。


修改了搜索目录后,必须要重启IDE,方能有效。

VisualC++ 2010使用方法:项目->属性->配置属性->VC++目录,将VLD安装目录下的文件夹添加到对应的目录中去。

其他版本IDE配置方法类似。

使用方法:

1、在源文件中包含进vld.h头文件,注意要加在stdafx.h之后。
2、如果一个或多个DLL要检查内存泄露,需要把vld.h在DLL的至少一个源文件中include。
3、build Debug版本的程序。

内存检测的报告会在程序退出后,在调试程序的输出窗口显示,双击报告中的源文件行号会定位到出现内存泄露的一行。

实例参考

#include "stdafx.h"
#include "vld.h"


int _tmain(int argc, _TCHAR* argv[])
{
	int *p=new int;
	int l=9;
	p=&l;
	system("pause");
	return 0;
}
检测报告:
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00000000003AA170: 4 bytes ----------
  Call Stack:
    f:\my documents\visual studio 2010\projects\leaktest\leaktest\leaktest.cpp (10): LeakTest.exe!wmain + 0xA bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crtexe.c (552): LeakTest.exe!__tmainCRTStartup + 0x19 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crtexe.c (371): LeakTest.exe!wmainCRTStartup
    0x000000007761652D (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0xD bytes
    0x0000000077C0C521 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
  Data:
    CD CD CD CD                                                  ........ ........

Visual Leak Detector detected 1 memory leak (56 bytes).
Largest number used: 56 bytes.
Total allocations: 56 bytes.
Visual Leak Detector is now exiting.
程序“[3540] LeakTest.exe: 本机”已退出,返回值为 0 (0x0)。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值