添加头文件和宏定义
#include <crtdbg.h>
#ifdef _DEBUG
#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)
#endif
在main函数最后添加
_CrtDumpMemoryLeaks();
没有内存泄露的测试代码和调试信息
#include <crtdbg.h>
#include <iostream>
#ifdef _DEBUG
#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)
#endif
int main()
{
int* num = new int(10);
delete num;
_CrtDumpMemoryLeaks();
}
存在内存泄露的测试代码和调试信息
#include <crtdbg.h>
#include <iostream>
#ifdef _DEBUG
#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)
#endif
int main()
{
int* num = new int(10);
//delete num;
_CrtDumpMemoryLeaks();
}