Windows下可包含以下的代码加入到KDetectMemoryLeak.h中,项目中包含此头文件,在DEBUG模式下运行,检测内存泄露问题。
/*
===========================================================================
功能:包含该头文件能自动检查VC++的内存泄露。
===========================================================================
*/
#pragma once
#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>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
// 在main()函数首行加入下面的函数
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );