vs 检测内存泄漏

来源:互联网 发布:今晚美国公布什么数据 编辑:程序博客网 时间:2024/05/17 07:48

网上有很多这个的说明,我只是总结了一下

#include <assert.h>#include <iostream>#ifdef _DEBUG    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)#else    #define DEBUG_CLIENTBLOCK#endif#define _CRTDBG_MAP_ALLOC#include <crtdbg.h>#ifdef _DEBUG    #define new DEBUG_CLIENTBLOCK#endif //此部分用于使_CrtDumpMemoryLeaks输出内存泄漏文件名和行号信息默认不会输出相关信息using namespace std;int main(int argc, char* argv[]){       int* p = new int;    _CrtDumpMemoryLeaks();    system("pause");    return 0;}

这里写图片描述

0 0