2011-09-01 09:41:29
在Windows平台下,检测内存泄漏的工具常用的一般有三种,MS C-Runtime Library内建的检测功能;外挂式的检测工具,诸如,Purify,BoundsChecker等
vc 7.0 有检测工具BoundChecker
也有其他的检测工具.
也可以用代码检测
#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
#endif
然后在要检测的代码前面加上:
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
在后面加上:
_CrtDumpMemoryLeaks();