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++ 程序的内存泄漏的检测方法及其实现进行探讨.其中包括 ...
随机推荐
- mongoose查询特定时间段文档的方法
db.collection.find({ time:{ "$gte": new Date('2014-01-24'), "$lte":new Date('201 ...
- ubuntu安装XHProf
1. 安装XHProf wget http://pecl.php.net/get/xhprof-0.9.2.tgz tar zxf xhprof-0.9.2.tgz cd xhprof-0.9.2 s ...
- mysql 的卸载、再安装与常用命令
1.卸载mysql.完全删除: 删除 mysqlsudo apt-get autoremove --purge mysql-server-5.0sudo apt-get remove mysql-se ...
- iOS判断机型
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef NS_OPTIONS(NSInteger,D ...
- DICOM医学图像处理:DCMTK在VS2012中的配置
背景: 近期因为项目须要,将原本的开发IDE环境由VS2008升级到了VS2012.本以为编译完毕后的DCMTK开源库能够直接从VS2008移植到VS2012.可是通过项目属性加入完包括文件夹和依赖库 ...
- objective-C学习笔记(四)函数成员:方法(函数)
函数分为: 全局函数(C语言函数) 成员函数(OBJC方法):实例方法 “-” 和类方法“+”的区别 //这里要区别静态变量(类变量).全局函数.常量的区别 OBJC里面,所有方法默认为公有方法.没 ...
- Random类短时间大量随机重复的问题
先声明一下,我是在那篇文章上看到的解决方法: http://dl.download.csdn.net/down10/20141103/4b173214e41ff3207305c2470524b0f3. ...
- ExtJs007最常用的查询方法
Ext.onReady(function () { Ext.create('Ext.panel.Panel', { title: '我的面板', width: '100%', height: 400, ...
- BZOJ 1192 鬼谷子的钱袋
题目如下 Description 鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政.有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一场拍卖会 ...
- 类中成员函数与数据成员private/pubic/protected
类中成员函数与数据成员private/pubic/protected