添加如下宏定义和头文件包含:
#ifdef _DEBUG
#define NEW_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new NEW_CLIENTBLOCK
#endif
在要检测内存泄漏的地方调用如下函数:
_CrtDumpMemoryLeaks();