VS 2013内存泄露检测的方法

来源:互联网 发布:向数据库中添加数据 编辑:程序博客网 时间:2024/05/16 13:02

实例:


#include "stdafx.h"

#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif  // _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif  // _DEBUG
/*
#include <stdlib.h>
#include <crtdbg.h>


#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif  // _DEBUG
*/

int _tmain(int argc, _TCHAR* argv[])
{

int *b = new int[10];
for (int i = 0; i < 10; ++i)
{
b[i] = i;
printf("%d\n", b[i]);

}
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
return 0;
}


然后启动调试,输出栏就会提示内存泄露的具体位置。

0 0