Wednesday, March 9, 2011

Discovering Memory Leaks

Title - Discovering Memory Leaks
Details - If you are working on a serious project, you will propably use a sophisticated memory manager which will discover memory leaks (along with their exact position in the code),
but if you just want to do a quick test in a small program, there is an easy way to let the debugger check for memory leaks:

- Include crtdbg.h in your project (this file is included in the
Microsoft Platform SDK
)
- At the beginning of main() or WinMain () put this code:

int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(flag);
This works in Visual C++ and, if you run the programm in debug mode, it will report memory leaks in the debug output window 
("Immediate Window" in the latest Visual Studio version). 
 
Reference-
http://tipsandtricks.runicsoft.com/Cpp/DiscoveringMemoryLeaks.html
 
Posted By : Preethymol K. S 

No comments:

Post a Comment