使用Visual调试库检测内存泄露
来源:互联网 发布:tensorflow 1.2 whl 编辑:程序博客网 时间:2024/05/29 11:03
#include <iostream>
using namespace std;
// 使用调试库
#define _CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>
// 重定义new运算符
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new (_NORMAL_BLOCK,__FILE__,__LINE__)
#define new DBG_NEW
#endif
#endif
class Simple{
public:
Simple()
{
m_pInt = new int();
}
virtual ~Simple()
{
delete m_pInt;
}
void setIntPtr(intinInt)
{
*m_pInt = inInt;
}
private:
int* m_pInt;
};
void dosomething(Simple*&outSimple)
{
outSimple = new Simple();
}
int _tmain(int argc,_TCHAR* argv[])
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |_CRTDBG_LEAK_CHECK_DF);
Simple* pSimple = new Simple();
// 这里导致内存泄露
dosomething(pSimple);
delete pSimple;
return 0;
}
该程序有两处内存泄露:
Detected memory leaks!
Dumping objects ->
c:\users\administrator\documents\visual studio 2013\projects\cpptestpro\cpptestpro\cpptestpro.cpp(34) : {200} normal block at 0x0057E1C8, 4 bytes long.
Data: < > 00 00 00 00
c:\users\administrator\documents\visual studio 2013\projects\cpptestpro\cpptestpro\cpptestpro.cpp(61) : {199} normal block at 0x0057E180, 8 bytes long.
Data: <X W > 58 CA F1 00 C8 E1 57 00
Object dump complete.
- 使用Visual调试库检测内存泄露
- 使用 Visual Leak Detector 检测内存泄露
- 使用Visual Leak Detector检测内存泄露
- 使用Visual Leak Detector检测内存泄露
- C++内存泄露调试检测
- 使用Visual Leak Detector for Visual C++ 捕捉内存泄露---Visual C++内存泄露检测—VLD工具使用说明
- 内存泄露调试之 visual leak detector 工具的使用
- 使用vld(visual leak detector)进行内存泄露调试
- VC使用CRT调试功能检测内存泄露的方法
- VISUAL STUDIO 检测内存泄露 (FROM MSDN)
- visual studio内存泄露检测方法
- C++内存泄露检测(Visual studio 2010)
- Visual Leak Detector检测内存泄露
- Visual Studio 2008 C++ 内存泄露检测
- 使用_CrtSetDbgFlag检测内存泄露
- 使用_CrtSetDbgFlag检测内存泄露
- 使用_CrtSetDbgFlag检测内存泄露
- 使用_CrtSetDbgFlag检测内存泄露
- C++连接MySQL
- 高效质数判断算法及其JS实现
- mysql无法远程访问10061错误(ubuntu 16.04 mysql 5.7.13)
- hdu5862 Counting Intersections
- 【机器学习】数据预处理
- 使用Visual调试库检测内存泄露
- Java+mysql用户注册登录
- DLL开发的问题
- 【PAT】1048. Find Coins
- convert 3D matrix into diagonal block matrix
- jsoncpp 使用详解
- LeetCode Game of Life 解题
- 学习hibernate_02_双向onetoone注解
- C++ SQL 语句格式化