Memory Leak Detection:在VS2008中检查内存泄露

CodeProject上有许多关于Memory Leak Dectection的代码,下面的链接便是其中之一,使用起来十分方便

http://www.codeproject.com/KB/cpp/MemLeakDetect.aspx 

 

对与MFC项目,只需要

1,将memleakdetect.h和memleakdetect.cpp添加到项目,

2,在**App.cpp添加对memleakdetect.h的引用

3,同样在**App.cpp为debug声明全局变量

 

下面是作者给出的一个demo project中**app.cpp文件的部分代码

 #include "stdafx.h" #include "MFCLeakerTest.h" #include "MFCLeakerTestDlg.h" #include "MemLeakDetect.h" // CMFCLeakerTestApp BEGIN_MESSAGE_MAP(CMFCLeakerTestApp, CWinApp) ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() // CMFCLeakerTestApp construction CMFCLeakerTestApp::CMFCLeakerTestApp() { int* pInteger; CLeakMemory* pMem; pMem = new CLeakMemory(); pInteger = new int; // TODO: add construction code here, // Place all significant initialization in InitInstance } // Detect Memory Leaks or comment #ifdef _DEBUG CMemLeakDetect memLeakDetect; #endif

 

 

你可能感兴趣的:(windows,leak,construction,initialization,command,mfc)