vs下檢測程式是否有記憶體洩露
阿新 • • 發佈:2020-12-10
新增標頭檔案和巨集定義
#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 ();
}