Visual leak detector, a memory leak detection tool under VC ++

Source: Internet
Author: User

: Http://www.codeproject.com/KB/applications/visualleakdetector.aspx

If you are using VC 2008/2010, you need to download the latest 2.0b,: http://vld.codeplex.com/or

 

Http://download.csdn.net/source/3229600

The usage of this tool is very simple, and the software documentation provides clear instructions:

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:

* Visual c ++ 8 and 9: 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 subdirectory from the visual leak detector installation directory. again, move it to the bottom of the list.
* Visual c ++ 7: 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 subdirectory from the visual leak detector installation directory. again, move it to the bottom of the list.
* Visual c ++ 6: Go to tools-> options-> 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 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 shoshould not matter which file you add the include statement. it also shocould not matter in what order the header is encoded 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 encoded in a source file, so VLD. h must be encoded ded after any precompiled headers.
2. if your program contains one or more DLLs that you wowould also like to check for memory leaks, then also include VLD. h in at least one source file from each DLL to be removed ded 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 encoded by limit 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 need ded in your source files when doing release builds. doing so will not result in any performance degradation or any other undesirable overhead.

It should be noted that the software is an open-source tool and is not a mature commercial product, so the ease of use is not very good and there are some minor problems, we still need to solve it by ourselves. The following are my problems and solutions:

1. After F5 runs the program, the system prompts "unable to locate the program Input Point ???? On the Dynamic Link Library dbghelp. dll"

Solution: Check the [Output] window to see which directory dbghelp. dll is loaded.
If you find "?. EXE ": content such as" C:/Windows/system32/dbghelp. dll "has been loaded.
The problem is that the program automatically loads dbghelp. dll in the system directory,
The dbghelp. dll of VLD is not loaded.
Solution: (1) Delete dbghelp. dll in the system directory or change its name temporarily. (2) Copy dbghelp. dll in the VLD installation path to the debug folder of your program.
In short, you only need to let the program load the dbghelp. dll of VLD. We recommend that you use this method (2) to avoid moving anything in the system directory ).
When using method (2), do not copy vld_x86.dll to the DEBUG directory. If copied, the program stack will overflow and crash.

NOTE: If vld_x86.dll cannot be loaded normally, it indicates that no environment variable is set, VLD is re-installed, and [Yes] is selected when the installer asks whether to set the environment variable.

2. The leaked location cannot be displayed and the CPP file and code line cannot be located. There are also a large number of false positives.

Example: Call Stack:
0x0041907c (file and line number not available): (function name unavailable)


Solution: the cause of this problem is that the VLD fails to find the. PDB file, resulting in a false alarm and the code location cannot be located. To solve this problem, we need to start with how to make VLD find the. PDB file.

(1) Ensure that the directory path of the VC project file does not contain Chinese characters or double-byte characters. (VLD cannot support Chinese path)
(2) check whether the. PDB file is generated normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.