查找内存泄露的方法

来源:互联网 发布:ableton live mac破解 编辑:程序博客网 时间:2024/05/30 13:42
这样一段小程序:
#define _CRTDBG_MAP_ALLOC //这里是必须要的
#include <iostream>
#include<stdlib.h> 
#include<crtdbg.h>//这里是必须要的
using namespace std;

int main()
{
cout<<"test"<<endl;
{
int* pInt = new int(10);
cout<<*pInt<<endl;
}

_CrtDumpMemoryLeaks();//这里是必须要的
system("pause");
return 0;
}

debug的输出如下,

Detected memory leaks!
Dumping objects ->
{119} normal block at 0x003B5D88, 4 bytes long.
 Data: <    > 0A 00 00 00 
Object dump complete.
0 0
原创粉丝点击