Flexible and freeCA major feature of the language, but this feature also has some unavoidable side effects, such as memory leakage. As we all know, memory leakage is complicated,ProgramDuring normal operation, you cannot see any exceptions, but it is exposed only when it runs for a long time or when a specific operation is repeated multiple times under a specific condition. Therefore, memory leakage is often hard to discover and solve.
Visual Leak Detector ( VLD ) Is used Visual c ++ Free memory leak detection tool. Http://www.codeproject.com/tools/visualleakdetector.asp Download, the software is used together with the user's project under test in the form of a library, because VLD Yespress Lgpl ( GNU lesser General Public License Protocol is open to external parties, so use VLD It is secure and you do not have to worry about copyright issues.
Vctester Is a suitable VC CodeThe white-box testing tool, with the help of its Script driver and script pile function, can easily initiate various tests, because memory leakage usually occurs in a specific operation Vctester And VLD Used in combination Vctester Simulate various application scenarios, VLD Detects Memory leakage in these scenarios.
Use VLD
download the zip zip package. The current maximum version is V1.0 . decompress the package and obtain VLD. h , vldapi. h , VLD. lib , vldmt. lib , vldmtdl L. lib , dbghelp. DLL . h copy the header file to VC default include directory, all . lib copy the file to VC the default lib directory completes the installation.
use VLD very simple. Only the CPP or C file VLD. h include the header file. The include statement must be placed at the beginning, if the current project defines pre-compiled head files (such as stdafx. h ), put it in " # include . After compilation, run the program in debug mode, view the output output window of VC , there will be " visual leak detector is now exiting. "indicates the printed information. Before this condition is met, if the current program has no memory leakage, " no memory leaks detected. "information is printed. However, if memory leakage occurs, the following information is printed:
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,VCThat is, automatically jump to the corresponding line of code, we can easily know which line has an error.
we can see that, VLD easy to use, anyone interested in its implementation principles can read VLD source code, for more information, see dofty Article : use visual leak detector detects memory leaks .