在debug模式下以F5运行:
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
//在入口函数中包含 _CrtDumpMemoryLeaks();
//即可检测到内存泄露
//以如下测试函数为例:
int main()
{
char* pChars = new char[10];
_CrtDumpMemoryLeaks();
return 0;
}
其他方法: 点击打开链接