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:

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.

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.

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.

Comments

I had a project run on debug version and had memory leak issue:So VLD was installed on VS2015 - and run with Remote debugger After add "vld.h" into project, but end up "exception" and could not pin point the memory leak....Please help.....

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?

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?

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.//

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:

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.

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."

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.

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.

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.

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'".

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?