VC++ 启用内存泄露检测

_CrtDumpMemoryLeaks()就是检测从程序开始到执行该函数进程的堆使用情况,通过使用_CrtDumpMemoryLeaks()我们可以进行简单的内存泄露检测。

#include "stdafx.h"
#include <stdlib.h>  
#include <crtdbg.h>   

#define _CRTDBG_MAP_ALLOC  
#define new  new(_CLIENT_BLOCK, __FILE__, __LINE__)

int _tmain(int argc, _TCHAR* argv[])
{
    int* leak = new int[10];
    _CrtDumpMemoryLeaks();
    system("pause");
    return 0;
}

输出:

posted @ 2021-06-16 09:47  钟齐峰  阅读(80)  评论(0编辑  收藏  举报