Click here to Skip to main content
15,791,050 members
Articles / Programming Languages / C++

Identify Memory Leaks in Visual CPP Applications

Rate me:
Please Sign up or sign in to vote.
4.26/5 (11 votes)
1 Nov 2015CPOL1 min read 10.2K   7   7
Identify Memory Leaks in Visual CPP Applications

Visual Leak Detector (VLD) is an easy to use memory leak detection system. The installation package can be downloaded from here.

After installation, it can be used with any C/C++ project simply by adding the following line to the code:

#include <vld.h>

When the program is executed under the Visual Studio debugger, Visual Leak Detector will output a memory leak report of the executed segment of the code, at the end of the debugging session. If memory leaks are detected, this report will point to the exact locations in the code segment, which allocated the leaked memory block.

The header file can be easily isolated from the rest of the source codes by guarding it with the pre-processor directive block. It can be made further user friendly by defining a separate Visual Studio build configuration for VLD. The steps are as follows:

  1. Include VLD header files(s) protected by a pre-processor directive.
    #ifdef _VLD_DEBUG
    #include <vld.h> //For memory leak detection.
    #endif  //_VLD_DEBUG
  2. Create a VLD specific Build Configuration for development purposes. Detailed steps to create a Build Configuration are available here.
  3. Under the new Build Configuration (example VLD_Debug), define the pre-processor directive which enables VLD specific headers.
    1. Right click on the project on Visual Studio Solution Explorer & select Properties. This will open the Property Page of the project.
    2. Expand the Configuration Properties node.
    3. Expand C\C++ node.
    4. Select Preprocessor. Enter preprocessor definition (example. "_VLD_DEBUG").
    5. Add the location of the vld.h header file to "includes" directory path of this configuration.
  4. Select VLD specific Build Configuration for development purposes.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Engineer MTT Network (Pvt.) Ltd.
Sri Lanka Sri Lanka
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionNeed for MLD Pin
geoyar3-Nov-15 11:54
professionalgeoyar3-Nov-15 11:54 
It is all OK but do we really need it? Seems that careful design with C++ smart pointers might do all work automatically releasing committed memory chunks.

SuggestionIf you use CRT Pin
den2k883-Nov-15 3:31
professionalden2k883-Nov-15 3:31 
GeneralMy vote of 1 Pin
SergV-SNV2-Nov-15 19:41
SergV-SNV2-Nov-15 19:41 
Suggestionmy vote - 1. You must put a reference Pin
SergV-SNV2-Nov-15 19:39
SergV-SNV2-Nov-15 19:39 
GeneralRe: my vote - 1. You must put a reference Pin
Duleeka Gunatilake2-Nov-15 20:59
Duleeka Gunatilake2-Nov-15 20:59 
GeneralRe: my vote - 1. You must put a reference Pin
BillW333-Nov-15 3:58
professionalBillW333-Nov-15 3:58 
GeneralMy vote of 5 Pin
PVX0072-Nov-15 8:42
PVX0072-Nov-15 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.