A. VLD Tools Overview
Visual Leak Detector (VLD) is a free memory leak detection Tool for Visual C + +. His features are: You can get the memory leak point of the call stack, if possible, you can also get the file and line number, you can get full data leakage memory, you can set the level of memory leak report, and is open source free.
two. VLD Download
Http://www.codeproject.com/tools/visualleakdetector.asp
This article is accompanied by a vld1.0 toolkit, which can be used after downloading the unpacked package.
three. VLD installation
Method One:
After decompression to get vld.h, vldapi.h, Vld.lib, Vldmt.lib, Vldmtdll.lib, Dbghelp.dll and other documents. Copy the. h file to the default include directory for Visual C + +, copy the. lib file to the default Lib directory of Visual C + +, copy the Dbghelp.dll to the running directory of your program, and the installation is complete.
Method Two:
After decompression to get vld.h, vldapi.h, Vld.lib, Vldmt.lib, Vldmtdll.lib, Dbghelp.dll and other documents. Copy the. h file and the. lib file to the directory where you want to detect the project file (for this project only), and copy the Dbghelp.dll to the running directory of your program. The installation is complete.
Four. VLD use
Vld.h is included in the. cpp file that contains the entry function. The following is an example of the source program (see appendix):
1. Add header file:
2. Compiling:
3. Run in debug mode: View the output information of the VC:
Where the memory leak resides |
4. View VC Output Information:
"Warning:visual Leak Detector detected meory leaks!"
5. If there is no memory leak, the information for this output is:
"No Memory leaks detected"
Five. Appendix
1. Test file
#include "Vld.h"
#include "iostream.h"
#include "stdio.h"
#include "Stdlib.h"
#include "string.h"
void Function1 (char *p)
{
char *ptmp = new char[255];
memset (ptmp, 0x0, 255);
strncpy (ptmp, p, 255);
//delete ptmp;
}
int Function2 (void)
{
Char acstring[] = "This is test!";
Function1 (acstring);
return 1;
}
void Function3 (void)
{
Function2 ();
}
int main (void)
{
cout << "Begin ......." << Endl;
Function3 ();
cout << "End ........" << Endl;
return 1;
}
2. Vld1.0 Tool Kit
3. For Linux memory leaks, you can use the Valgrind tool for detection.
Visual C + + memory leak detection-VLD tool usage instructions