Visual Leakdetector (VLD) is a free memory leak detection Tool for Visual C + +. It is characterized by: (1), it is free open source, using the LGPL protocol, (2), it can get the memory leak point of the call stack, you can get the file and line number, (3), it can get the full data leakage memory, (4), it can set the memory leak report level.
By default, the VLD feature is enabled only in debug mode.
When using, simply place the VLD header and Lib files in the project file.
Add # include "Vld.h" in source files that require detection of memory leaks
VLD can only be used under Windows, and it is applied in the C + + language.
You can set the location where the memory leak report is saved by modifying the Vld.ini file (reportfile option).
VLD seems to not support the Chinese path.
Each version of the VLD is suitable for different Vc/vs compilers, note that the appropriate version is selected.
1. Download the latest source code from HTTP://VLD.CODEPLEX.COM/SOURCECONTROL/LATEST#README.MD, unzip, contains the source, VS2010 engineering configuration, as well as some dependent libraries, such as dbghelp, etc.;
2. Open Vld_vs10.sln, under 32-bit/64-bit, compile debug and release under VLD Project respectively, will generate the Bin folder in the current directory, containing the corresponding library files;
3. New Console Project Vldtest, run under Debug, code as follows:
Stdafx.cpp:
#include "stdafx.h" #ifdef _debug#pragma comment (lib, "... /.. /.. /src/vld/bin/win32/debug/vld.lib ") #else//#pragma comment (lib,". /.. /.. /src/vld/bin/win32/release/vld.lib ") #endif
VLDtest.cpp:
#include "stdafx.h" #include ". /.. /src/vld/vld.h "#include <iostream>using namespace std;void fun () {char* tmp = new Char[10];memset (tmp, 0, 10);} int main (int argc, char* argv[]) {fun ();cout<< "ok!" <<endl;return 0;}
4. Run the prompt, "cannot start this program because the computer is missing Vld_x86.dll", the workaround, copy Bin/win32/debug/vld_x86.dll to vldtest execution directory or vld_ The X86.dll path is added to the system environment variable;
5. Run the prompt, "application does not start normally (0xc0150002)",/setup/dbghelp/in the source code Dbghelp.dll and Microsoft.DTfW.DHL.manifest two files under the x86 folder can be copied to the Vldtest execution directory;
6. Press F5 directly, you can display the memory leak in the Output window information, including the memory leak of the file name and line number, double-click to locate the specific location of the memory leak;
7. Or run directly, the relevant information can be displayed in the Command Line window;
8. Memory leak information can also be written to the file, the source code in the Vld.ini file copy to the Vldtest project directory, that is, with vldtest.vcxproj directory, modify the Vld.ini file option parameters, Reportfile =. \. /.. /.. /lib/dbg/x86_vc10/memory_leak_report.txt,reportto =both (Original Reportto = debugger), once rerun, generates a memory_leak_ in the execution directory Report.txt file, or copy the Vld.ini file to the execution directory, run the Vldtest[dbg_x86_vc10].exe file to generate a report file;
9. Run under release, VLD does not work, vldtest works without any configuration and adjustment;
no need to compile the source code, directly from the http://vld.codeplex.com/releases download, and then install, which contains the required library and header files.
The memory leak information shown in the figure for running the test code:
Example of use of memory leak detection Tool VLD in VS2010