Memory leak is defined as the failure to correctly deallocate the memory that was previously allocated and it is a hard to detect bug in C++ applications. The program that leaks large amount of memory or leak progressively may decrease the performance of your system. These kinds of memory leaks make unexpected crashes in our applications and the most difficult part is to reproduce the defect and find out the root cause of same. So it is always better to analyze the memory leaks together with the functionality testing of our application. Lots of 3rd party tools are available for detecting memory leaks in our C++ code. AQTime is one of the best tools I ever used.But in this post I would like to discuss about enabling memory leak detection using Windows APIs.
The visual studio debugger along with C Run-Time Libraries (CRT) can help us to detect memory leaks in our code.
To enable the debug heap functions, include the following statements in your program:
#define _CRTDBG_MAP_ALLOC #include "stdlib.h" #include "crtdbg.h"
you can place a call to _CrtDumpMemoryLeaks before an application exit point to display a memory-leak report when your application exits: