如何捕捉内存泄露
#include "stdafx.h"#include <iostream>using namespace std;#ifdef _DEBUG#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)#else#define DEBUG_CLIENTBLOCK#endif#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>#include <string.h>#include <stdio.h>#ifdef _DEBUG#define new DEBUG_CLIENTBLOCK#endifint main(){_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);int *p;p = new int;_CrtDumpMemoryLeaks();system("pause");return 0;}在output窗口可以看到内训泄露的信息。
页:
[1]