QT VS检测内存泄漏


参考链接1: http://blog.csdn.net/dizuo/article/details/6030676
| 今天在QT_VP中简单地添加了内存泄露检测语句:
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 结果出来一大堆的内存泄露,着实吓了一跳,跟踪了一天,逐段派出,最后还是感觉没问题(还是比较自信代码质量的O(∩_∩)O哈哈~)。。。最后上网一查,在vs中,先是进行内存泄露报告,然后才卸载Qt的dll,释放申请的资源。所以才会出现这种情况。 |
系统环境:
|
#ifndef SET_DEBUG_NEW_H
#define SET_DEBUG_NEW_H
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
#endif // end SET_DEBUG_NEW_H
|
|
#include "test_memoryleak.h"
#include <QtGui>
#include "setdebugnew.h"
test_memoryLeak::test_memoryLeak(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
btn1 = new QPushButton("test1", this);
btn2 = new QPushButton("close", this);
QWidget *memLeak_test = new QWidget;
connect(btn2, SIGNAL(clicked()), this, SLOT(close()));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(btn1);
layout->addWidget(btn2);
setLayout(layout);
}
test_memoryLeak::~test_memoryLeak()
{
}
|
|
#include "test_memoryleak.h"
#include <QtGui/QApplication>
#include "setdebugnew.h"
int main(int argc, char *argv[])
{
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
int *i = new int;
QApplication a(argc, argv);
test_memoryLeak w;
w.show();
return a.exec();
}
|
|
{1220} normal block at 0x016605F8, 552 bytes long.
Data: < f > 83 00 00 00 83 00 00 00 08 06 66 01 CD CD CD CD
{1215} normal block at 0x01660398, 292 bytes long.
Data: < eH f x=g> 94 85 A2 65 48 03 66 01 00 00 00 00 C4 78 3D 67
.\test_memoryleak.cpp(12) : {1214} client block at 0x01660348, subtype 0, 20 bytes long.
.
.
.
{289} normal block at 0x01388960, 56 bytes long.
Data: < 8 > 03 00 00 00 88 8A 38 01 00 CD CD CD 00 00 00 00
.\main.cpp(12) : {285} client block at 0x013872B0, subtype 0, 4 bytes long.
Data: < > CD CD CD CD
Object dump complete.
|
方法二:




|
#include "test_memoryleak.h"
#include <QtGui/QApplication>
#ifdef _DEBUG
#include "vld.h"
#endif
#include "setdebugnew.h"
int main(int argc, char *argv[])
{
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
int *i = new int;
QApplication a(argc, argv);
test_memoryLeak w;
w.show();
return a.exec();
}
|
|
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x007F72B0: 4 bytes ----------
Call Stack:
c:\users\ajaxhe\desktop\program\qt\practice\test_memoryleak\test_memoryleak\main.cpp (17): test_memoryLeak.exe!main + 0x10 bytes
C:\Qt\4.7.4\src\winmain\qtmain_win.cpp (131): test_memoryLeak.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): test_memoryLeak.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): test_memoryLeak.exe!WinMainCRTStartup
0x76B9ED6C (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77D1377B (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xEF bytes
0x77D1374E (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xC2 bytes
Data:
CD CD CD CD ........ ........
---------- Block 4 at 0x00CA0348: 20 bytes ----------
Call Stack:
c:\users\ajaxhe\desktop\program\qt\practice\test_memoryleak\test_memoryleak\test_memoryleak.cpp (12): test_memoryLeak.exe!test_memoryLeak::test_memoryLeak + 0x10 bytes
c:\users\ajaxhe\desktop\program\qt\practice\test_memoryleak\test_memoryleak\main.cpp (20): test_memoryLeak.exe!main + 0x17 bytes
C:\Qt\4.7.4\src\winmain\qtmain_win.cpp (131): test_memoryLeak.exe!WinMain + 0x12 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): test_memoryLeak.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): test_memoryLeak.exe!WinMainCRTStartup
0x76B9ED6C (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77D1377B (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xEF bytes
0x77D1374E (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xC2 bytes
Data:
04 7C FB 00 98 03 CA 00 E0 7B FB 00 00 00 CD CD .|...... .{......
50 04 CA 00 P....... ........
Visual Leak Detector detected 2 memory leaks (96 bytes).
Largest number used: 260 bytes.
Total allocations: 260 bytes.
Visual Leak Detector is now exiting.
|
http://blog.csdn.net/itjobtxq/article/details/21785885
QT VS检测内存泄漏的更多相关文章
- Qt creator 搭配 valgrind 检测内存泄漏
继上次重载operator new检测内存泄漏失败之后,妥协了.决定不管是否是准确指明哪一行代码出现内存泄漏,只要告诉我是否有泄漏就行了,这样就没有new替换的问题.在开发中,总是一个个小功能的开发. ...
- Android性能优化之利用LeakCanary检测内存泄漏及解决办法
前言: 最近公司C轮融资成功了,移动团队准备扩大一下,需要招聘Android开发工程师,陆陆续续面试了几位Android应聘者,面试过程中聊到性能优化中如何避免内存泄漏问题时,很少有人全面的回答上来. ...
- 使用Visual Leak Detector检测内存泄漏[转]
1.初识Visual Leak Detector 灵活自由是C/C++语言的一大特色,而这也为C/C++程序员出了一个难题.当程序越来越复杂时,内存的管理也会变得越加复杂,稍有不慎就会出现内存问题 ...
- monkey检测内存泄漏
monkey中检查内存泄漏,实际上是对一个操作多次操作后看内存情况,内存泄漏具体的原理可百度,现在我们梳理检测内存泄漏的方法: 测试前你需要安装: 1.MAT分析工具 2.使用工具事实监控内存指标,现 ...
- VC使用CRT调试功能来检测内存泄漏
信息来源:csdn C/C++ 编程语言的最强大功能之一便是其动态分配和释放内存,但是中国有句古话:“最大的长处也可能成为最大的弱点”,那么 C/C++ 应用程序正好印证了这句话.在 C/C+ ...
- 如何在linux下检测内存泄漏
之前的文章应用 Valgrind 发现 Linux 程序的内存问题中介绍了利用Linux系统工具valgrind检测内存泄露的简单用法,本文实现了一个检测内存泄露的工具,包括了原理说明以及实现细节. ...
- 重载new和delete来检测内存泄漏
重载new和delete来检测内存泄漏 1. 简述 内存泄漏属于资源泄漏的一种,百度百科将内存泄漏分为四种:常发性内存泄漏.偶发性内存泄漏.一次性内存泄漏和隐式内存泄漏. 常发性指:内存泄漏的代 ...
- Vc 检测内存泄漏
启用内存泄漏检测 检测内存泄漏是 C/c + + 调试器和 C 运行时库 (CRT) 的主要工具调试堆函数. 若要启用调试堆的所有函数,在 c + + 程序中,按以下顺序包含以下语句: C++复制 # ...
- 如何在linux下检测内存泄漏(转)
本文转自:http://www.ibm.com/developerworks/cn/linux/l-mleak/ 本文针对 linux 下的 C++ 程序的内存泄漏的检测方法及其实现进行探讨.其中包括 ...
随机推荐
- Checking Network Configuration requirements Failed
安装oracle执行检查,出现 Checking Network Configuration requirements ... Check complete. The overall result o ...
- mysql 的卸载、再安装与常用命令
1.卸载mysql.完全删除: 删除 mysqlsudo apt-get autoremove --purge mysql-server-5.0sudo apt-get remove mysql-se ...
- javascript中对变量类型的推断
本文正式地址:http://www.xiabingbao.com/javascript/2015/07/04/javascript-type 在JavaScript中,有5种基本数据类型和1种复杂数据 ...
- 关于js封装框架类库之DOM操作模块(一)
在前端开发的过程中,javascript极为重要的一个功能就是对DOM对象的操作,而对其封装就是为了更好地进行DOM操作,提高浏览器的支持效率 现在给出一个案例:页面创建三个div,然后给其添加样式 ...
- nodejs入门demo
demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...
- ThinkPHP常量参考
常用常量 APP_NAME 当前项目名称 APP_PATH 当前项目路径 GROUP_NAME 当前分组名称 MODULE_NAME 当前Action模块名称 ACTION_NAME 当前操作的名称 ...
- PHP获取网址的PR值
PR值是google衡量网站的重要标准之一,根据google提供的结果获取pr值,如:http://toolbarqueries.google.com.hk/tbr?client=navclient- ...
- hdu 4704 Sum 费马小定理
题目链接 求2^n%mod的值, n<=10^100000. 费马小定理 如果a, p 互质, 那么a^(p-1) = 1(mod p) 然后可以推出来a^k % p = a^(k%(p-1) ...
- 什么是core dump?(转)
什么是Core Dump? 今天调试一个程序, 用到了core dump, 于是写出来, 记于此.什么是Core Dump?Core的意思是内存, Dump的意思是扔出来, 堆出来.开 发和使用Uni ...
- 帝国cms7.0判断字段为空,显示为不同
在一些情况下,我们的字段会留空,但是又不希望内容模板上只显示空.比如,在后台,如添加作者为小明,则显示小明,不填作者则显示"佚名",我们可以用以下代码. <? if($nav ...