申请的内存多次释放内存泄漏释放的内存不是申请时的地址释放空指针释放一个内存块,但继续引用其中的内容越界访问 内存泄漏检测工具 VisualC++ debugger 和 CRT 库 第一步:包含以下头文件
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.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