博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Visual Leak Detector for Visual C++ 捕捉内存泄露
阅读量:6929 次
发布时间:2019-06-27

本文共 3972 字,大约阅读时间需要 13 分钟。

1、下载vlc

2、创建应用并配置

c/c++ -> General -> Additional Include Directories = C:\Program Files (x86)\Visual Leak Detector\include

Linker -> General -> Additional Library Directories = C:\Program Files (x86)\Visual Leak Detector\lib\Win32

3、捕捉内在泄露

#include "stdafx.h"#ifdef _DEBUG   #include "vld.h"#endifint _tmain(int argc, _TCHAR* argv[]){    char* c1 = new char[100];    char* c2  =(char*)malloc(200);    char c3[1000];    //delete[] c1;    //free(c2);    return 0;}

输入如下:

Visual Leak Detector Version 2.2.3 installed.WARNING: Visual Leak Detector detected memory leaks!---------- Block 1 at 0x008CD6F8: 100 bytes ----------  Call Stack:    c:\users\enost_000\desktop\consoleapplication1\consoleapplication1\consoleapplication1.cpp (12): ConsoleApplication1.exe!wmain + 0x7 bytes    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (533): ConsoleApplication1.exe!__tmainCRTStartup + 0x19 bytes    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ConsoleApplication1.exe!wmainCRTStartup    0x74EE8543 (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0xE bytes    0x770EAC69 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x85 bytes    0x770EAC3C (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x58 bytes  Data:    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD                                                  ........ ........---------- Block 2 at 0x008CD798: 200 bytes ----------  Call Stack:    c:\users\enost_000\desktop\consoleapplication1\consoleapplication1\consoleapplication1.cpp (13): ConsoleApplication1.exe!wmain + 0xD bytes    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (533): ConsoleApplication1.exe!__tmainCRTStartup + 0x19 bytes    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ConsoleApplication1.exe!wmainCRTStartup    0x74EE8543 (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0xE bytes    0x770EAC69 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x85 bytes    0x770EAC3C (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x58 bytes  Data:    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........    CD CD CD CD    CD CD CD CD                                   ........ ........Visual Leak Detector detected 2 memory leaks (372 bytes).Largest number used: 372 bytes.Total allocations: 372 bytes.Visual Leak Detector is now exiting.The program '[0x262C] ConsoleApplication1.exe' has exited with code 0 (0x0).

 

4、qt也vlc

  vlc只支持vc编译器,所以 qt的话只能够使用vc编译器捕捉并解决内存泄露之后,再考虑使用mingw(gcc/g++)编译程序。

转载地址:http://vxpjl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
提权【SQL语句直接开启3389】
查看>>
理顺 JavaScript (2) - 应先掌握的四个方法
查看>>
Linux下Oenssl命令及搭建私有CA
查看>>
百度地图计算两点之间距离
查看>>
iPhone 通过UIRequiredDeviceCapabilities指定程序适用于哪些设备
查看>>
记录com.google.code.maven-replacer-plugin找不到文件
查看>>
spring mvc
查看>>
jenkins git maven 自动部署
查看>>
Linux运维不可不知的性能监控和调试工具
查看>>
XAML数据绑定(Data Binding)
查看>>
服务器SSL/TLS快速检测工具TLLSSLed
查看>>
012 出牌显示
查看>>
Zabbix agent自动注册功能实现主机批量监控
查看>>
float display特性介绍
查看>>
多个网卡绑定成一块虚拟网卡
查看>>
phpweb不能成功运行的原因
查看>>
ceph 创建用户,秘钥
查看>>
Valgrind使用
查看>>
马上着手开发iOS应用程序文章总结
查看>>