Using Visual Leak Detector

This section briefly describes the basics of using Visual Leak Detector (VLD).

Important! : Before using VLD with any Visual C++ project, you must first add the Visual Leak Detector include and library directories to the Visual C++ include and library directory search paths:
For all compiler versions take care to ensure that no junk characters get added when you add the include and library paths. If you browse to the "Program Files(x86) folder using the dialog box provided by Visual Studio and select it you could end up seeing the "%" replacing the "(".

And remember to close and open the Visual Studio IDE once you have modified the default include and library paths which the compiler and linker would always look at.
  • Visual C++ 2010/2012/2013: Go to View ->Property Manager, select Microsoft.Cpp.Win32.user. Select VC++ Directories and then "Include files" from the tree. Add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select "Library files" from the drop-down menu and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list. Repeat for Microsoft.Cpp.x64.user, but select lib\Win64 subdirectory instead.
  • Visual C++ 2005 and 2008: Go to Tools -> Options -> Projects and Solutions -> VC++ Directories. Select "Include files" from the "Show Directories For" drop-down menu. Add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select "Library files" from the drop-down menu and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list.
  • Visual C++ 2003: Go to Project Properties -> C/C++ -> General -> Additional Include Directories and add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select Additional Library Directories and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list.

To use VLD with your project, follow these simple steps:
  1. In at least one C/C++ source file from your program, include the vld.h header file. It should not matter which file you add the include statement to. It also should not matter in what order the header is included in relation to other headers. The only exception is stdafx.h (or any other precompiled header). A precompiled header, such as stdafx.h, must always be the first header included in a source file, so vld.h must be included after any precompiled headers.
  2. If your program contains one or more DLLs that you would also like to check for memory leaks, then also include vld.h in at least one source file from each DLL to be included in leak detection.
  3. Build the debug version of your program.

Note: Unlike earlier (pre-1.9) versions of VLD, it is now acceptable to include vld.h in every source file, or to include it in a common header that is included by many or all source files. Only one copy of the VLD code will be loaded into the process, regardless of how many source files include vld.h.
VLD will detect memory leaks in your program whenever you run the debug version. When you run the program under the Visual C++ debugger, a report of all the memory leaks detected will be displayed in the debugger's output window when your program exits (the report can optionally be saved to a file instead, see ReportFile under Configuration Options). Double-clicking on a source file's line number in the memory leak report will take you to that file and line in the editor window, allowing easy navigation of the code path leading up to the allocation that resulted in the memory leak.

Note: When you build release versions of your program, VLD will not be linked into the executable. So it is safe to leave vld.h included in your source files when doing release builds. Doing so will not result in any performance degradation or any other undesirable overhead.

Last edited Dec 25, 2013 at 4:20 PM by KindDragon, version 7


tlguo Mar 21 at 11:35 PM 
I have a native DLL which is loaded by a C# managed program and I suspect memory leaks in the native DLL. How can I use VLD to detect in memory leak in the native DLL? That native DLL allocates memorys after the function InitModule() and is supposed to withdraw all memory in calling unloadModule(). I insert VLDEnable() at the begining of initModule() function of my native DLL and VLDReportLeaks() at the end of the unloadModule() but I still can't see any report message in the output panel. Why?

BubuS24 Apr 24, 2015 at 10:16 AM 
Would be nice to have the VLD version accessible at program compiletime.
I'm currently using VLD 2.4rc2 with VC++ 2013. Any means available?

andrewjturner Jan 12, 2015 at 8:03 AM 
Debugging my DLL running under Excel 2010 under VS2008 Express. After installing VLD on VS2008 Expresss, when I debug by opening the Excel sheet and loading my DLL, I now get endless Unhandled Exception pop-ups in the debuigger which prevent me from continuing - I can only Continue (up pops another) or break. When I remove VLD, the problem goes away. Anyone any ideas please?

cvolpe Sep 2, 2014 at 3:31 PM 
I installed without a problem. I created a dummy bare-bones 64-bit console application using VS2013 on Windows7. I added only three lines to the main program file created by the wizard. The resulting code looks like this:

// TestVLD.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <vld.h>

int _tmain(int argc, _TCHAR* argv[])
char *testLeak = new char[1000000];
testLeak = nullptr;
return 0;

When I run in the debugger, the PDB files for the main program load fine, but there are a bunch of "Cannot find or open the PDB file" messages pertaining to MS built-in OS files in C:\Windows\System32. After those messages, the only report I get from VLD is the following:

Visual Leak Detector Version 2.3 installed.
No memory leaks detected.
Visual Leak Detector is now exiting.
The program '[7840] TestVLD.exe' has exited with code 0 (0x0).

I would have thought that VLD would have no problem detecting that blatant memory leak. What am I doing wrong?

DTang33 Aug 12, 2014 at 12:08 AM 
Hi all, I'm new to VLD. I'm debugging an application with known memory leak (~20 M). I just installed Visual Leak Detector, configured vld with all required setting, and ran it with my program. However, I did not get any report of memory leak from Visual Studio Output; instead, I found VLD module could not function due to following warning from the Visual Studio Output:
WARNING: Visual Leak Detector: A module, igdumdim32.dll, included in memory leak detection
does not have any debugging symbols available, or they could not be located.
Function names and/or line numbers for this module may not be available.

Any thought how I can fix this problem? Thanks.

123456 Mar 25, 2014 at 10:32 AM 
I was getting the error 0xc0150002, copying the files dbghelp.dll and Microsoft.DTfW.DHL.manifest from the dbghelp folder to the bin folder solved the problem.
Nice tool, thanks!

brewmanz Feb 5, 2014 at 9:04 PM 
I'm using VS2012 with Win7(x64) and having some issues setting VLD up:
- Initial installation went fine.
- "View ->Property Manager" needed "View ->Other Windows -> Property Manager"
- "select Microsoft.Cpp.Win32.user" I have absolutely no idea where or how to do this. Property Manager is an empty form saying "No Visual C++ project is loaded" and its Properties (only active part I have found) says "There are no property pages for the selection."

polomora Nov 12, 2013 at 9:12 AM 
Since my last comment I've started using VLD with VS2012. Compared with VS2008, the time to shutdown our application (when VLD does its magic to collate any outstanding memory leaks) has lengthened enormously, from about 2 minutes to about 30 minutes. When VLD is disabled via the vld.ini config file, the problem disappears, so this confirms that VLD is the problem.

polomora Jul 2, 2013 at 3:23 PM 
On further use, I noticed that the summary total of the number of bytes leaked reported by VLD does not agree with the sum of the reported leaked bytes. The summary number of leaks does agree.

I tested this using the following options:
VLD = on
AggregateDuplicates = no
ForceIncludeModules =
MaxDataDump = 32
MaxTraceFrames =
ReportEncoding = ascii
ReportFile = W:\Main\EnsorApplication\Castor\Build\VC90NT\Castor\Win32\Debug\vld_leak_report.txt
ReportTo = file
SelfTest = off
StackWalkMethod = fast
StartDisabled = no
TraceInternalFrames = no
SkipHeapFreeLeaks = no

At the end of the generated report:
Visual Leak Detector detected 11470 memory leaks (774260 bytes).

When I use scripts to calculate these figures for myself
cat /cygdrive/c/Users/21ppm/Desktop/vld_leak_report.txt | grep "\-\- Block" | wc -l
11470 (correct)
cat /cygdrive/c/Users/21ppm/Desktop/vld_leak_report.txt | grep "\-\- Block" | cut -f2 -d':' | cut -f2 -d' ' | awk 'a+=$1; END{print a}'
361340 (reported total was 774260)

polomora Jun 27, 2013 at 7:19 AM 
Also registered with CodePlex just to thank you for such a useful tool. I used it with VS2008, and it worked like a charm.

One thing that is unclear in the Documentation -> Configuration Options section. This section states that a a local configuration of VLD can be configured by copying a version of the vld.ini configuration file to the "program's working directory". Is this the directory where the executable program and (optiionally) its DLLs are located? I tried this, and it didn't work. So i've had to configure VLD using the master copy of vld.ini in the VLD installation directory.

andersmw May 3, 2013 at 7:46 PM 
the "failed to initialize properly" error was not cured for me.. I feel I've been __declspec-ed.

JPDworkin Mar 9, 2013 at 7:35 AM 
After a little fiddling I was able to get your tool working and found my leak problem. A very nice job. Here are the issue I found for my application/installation so you can improve the tool and documentation:
1 - I work at a large corporation with strict policies. When I tried to run my application with VLD enabled, I got an 'application failed to initialize properly' error on startup. This was finally cured by using: CACLS "C:\software\Visual Leak Detector\bin" /E /G BUILTIN\Users:R on the command line.

2 - The report did not reliably appear unless I explicitly added a call to VLDEnable in my main InitInstance and calling VLDReportLeaks as another commenter posted above.

raananb Feb 23, 2013 at 7:38 AM 
The instructions for Visual C++ 2010 do not apply as such to Visual C++ 2010 Express.
Some modifications would help:
1. In Properties management, you must select 'Debug | Win32' (in my case) before you can select 'VC++ Directories'.
2. Once VC++ Directories is selected, the wording '"include file" from the tree' is imprecise: replace with "add VLD/Include in 'Include Directories'".

3axap Nov 23, 2012 at 11:58 AM 
You may need to add VLDEnable() function call somewhere in your code to enable the detector or VLDReportLeaks() to create a report. Though the report will appear only when application exits.

mjrtstr Nov 7, 2012 at 1:42 AM 
Installed vld, no problem. Specifically set a function to cause a memory leak. Within that .cpp file, included <vld.h>. Called the known memory leaking function multiple times. Exited the program. NOTHING IN THE DEBUG OUTPUT WINDOW WHATSOEVER. What am I missing?

InsideOutCloud Jun 8, 2012 at 3:56 PM 
Just as a note, the setup directions for Visual Studio 2010 also work for Visual Studio 11