Check for Memory leakage in C ++-check through tools

Source: Internet
Author: User

Visual Leak Detector (VLD) is a free memory leak detection tool for Visual C ++. You can open the source from the GNU lesser General Public License protocol, therefore, using VLD is secure and you do not have to worry about copyright issues.

 

Use VLD

Download the VLD zip package from the website. The current maximum version is V1.0. decompress the package to obtain the VLD. h. vldapi. h. VLD. lib, vldmt. lib, vldmtdll. lib, dbghelp. DLL files, put all these. copy the H header file to the default include directory of VC, and copy all. copy the Lib file to the default lib directory of VC, and the installation is complete.

VLD is easy to use. You only need to include the VLD. h header file in the CPP or C file that contains the entry function. This include statement must be placed at the beginning. If the current project defines a pre-compiled head file (such as stdafx. h), it can be placed after the "# include <stdafx. h>" statement. After the program is compiled normally and run in debug mode, when the program is running, check the output window of VC and see "visual leak detector is now exiting. "A printed message. If the current program has no memory leakage before this condition information," no memory leaks detected. "Information printing, but if there is memory leakage, there will be similar information printing:

C: "vctester21" sample "vc6" samplemain. C (80): Main

Crt0.c (206): maincrtstartup

0x7c816fd7 (file and line number not available): registerwaitforinputidle

Data:

CD ................

Visual leak detector detected 1 memory leak.

This information indicates the function and source file number where the current Memory leakage occurs, and the address, length, and current memory value of the leaked memory block. Double-click the prompt message indicating the source code line. VC automatically jumps to the corresponding code line, so we can easily know which line has an error.

It can be seen that VLD is easy to use. If you are interested in its implementation principle, you can read the VLD source code.

Http://www.codeproject.com/tools/visualleakdetector.asp.

 

# Include "stdafx. H "<br/> # include <VLD. h> </P> <p> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> char * Ptest = new char [10]; </P> <p> return 0; <br/>}

 

From the output window, we can see memory leakage:

Visual leak detector version 1.0 installed (multithreaded DLL ).
Warning: Visual leak detector detected memory leaks!
---------- Block 109 at 0x003acec8: 10 bytes ----------
Call Stack:
E:/example/memoryleak/Memoryleak. cpp (10): Wmain
F:/RTM/vctools/crt_bld/self_x86/CRT/src/crtexe. C (583): _ tmaincrtstartup
F:/RTM/vctools/crt_bld/self_x86/CRT/src/crtexe. C (403): wmaincrtstartup
0x7c816fd7 (file and line number not available): registerwaitforinputidle
Data:
CD ................

Visual leak detector detected 1 memory leak.
Using memoryleak.exe ":" C:/Windows/system32/dbghelp. dll "has been uninstalled"
Using memoryleak.exe ":" C:/Windows/system32/version. dll "has been uninstalled"
Visual leak detector is now exiting.
The program "[5056] memoryleak.exe: Local" has exited and the returned value is 0 (0x0 ).

 

 

It is very convenient for us to find out the memory leak! You have time to study the source code of this tool. Pai_^

 

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.