在VS2012中添加部分代码,可以起到检测内存泄露的作用。

今天刚刚收到的解决办法,原理还不是很清楚。先分享出来

 

1. 头文件中添加以下代码

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

2. main函数中添加

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);  
/* 何问起 hovertree.com */

程序在DEBUG模式下运行时,就可以在输出窗口中看到可能出现的内存泄露信息

推荐:http://www.cnblogs.com/roucheng/p/cpphong.html

相关文章:

  • 2021-12-05
  • 2021-08-20
  • 2021-06-24
  • 2021-08-24
  • 2021-06-29
  • 2021-11-18
  • 2021-10-25
猜你喜欢
  • 2021-08-04
  • 2021-05-19
  • 2021-11-18
  • 2021-07-01
  • 2021-09-20
  • 2022-01-03
  • 2021-07-27
相关资源
相似解决方案