Visual C++ debugger 和 CRT库
第一步:包含以下头文件
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtbdg.h>
第二步:接管new操作符
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new (_NORMAL_BLOCK, _FILE_, _LINE_)
#define new DBG_NEW
#endif
#endif
第三步:在代码结束处输出内存泄漏消息
_CrtDumpMemoryLeaks();
内存泄漏工具:
Windows:Purify,BoundsCheaker,Deleaker,VisualLeak Detector(VLD),
Linux平台:Valgrind memcheck