Flexibility and freedom are a major feature of the C language, but this feature also brings unavoidable side effects, such as memory leakage. As we all know, the problem of Memory leakage is complicated. When a program runs normally, you cannot see any exceptions, but it runs for a long time or when a specific operation is repeated multiple times under a specific condition, it is exposed. Therefore, memory leakage is often hard to discover and solve.
Visual Leak Detector (VLD) is a free memory leak detection tool for Visual C ++.
Lesser General Public License) protocol is open source, so it is safe to use VLD without worrying about copyright issues.
Vctester is a white-box testing tool suitable for VC code. With its Script driver and script pile function, it can easily initiate various tests, because memory leakage usually occurs under specific operations, vctester is used in combination with VLD. vctester simulates various application scenarios. VLD detects whether memory leakage occurs in these scenarios.
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), put it in "# include
<Stdafx. h>. After the program is compiled normally and run in debug mode, check the output window of VC when the program is running.
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 or refer to dofty's article: using Visual
Leak detector detects Memory leakage.
Tip: http://www.cnblogs.com/dwjaissk/archive/2007/11/08/952927.html