原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications
基于CPOL License
Visual Leak Detector (VLD) is an easy to use memory leak detection system. The installation package can be downloaded from here.
After installation, it can be used with any C/C++ project simply by adding the following line to the code:
#include <vld.h>
When the program is executed under the Visual Studio debugger, Visual Leak Detector will output a memory leak report of the executed segment of the code, at the end of the debugging session. If memory leaks are detected, this report will point to the exact locations in the code segment, which allocated the leaked memory block.
The header file can be easily isolated from the rest of the source codes by guarding it with the pre-processor directive block. It can be made further user friendly by defining a separate Visual Studio build configuration for VLD. The steps are as follows:
- Include VLD header files(s) protected by a pre-processor directive.
Hide Copy Code
#ifdef _VLD_DEBUG #include <vld.h> //For memory leak detection. #endif //_VLD_DEBUG - Create a VLD specific Build Configuration for development purposes. Detailed steps to create a Build Configuration are available here.
- Under the new Build Configuration (example
VLD_Debug), define the pre-processor directive which enables VLD specific headers.- Right click on the project on Visual Studio Solution Explorer & select Properties. This will open the Property Page of the project.
- Expand the Configuration Properties node.
- Expand C\C++ node.
- Select Preprocessor. Enter preprocessor definition (example. "
_VLD_DEBUG"). - Add the location of the vld.h header file to "includes" directory path of this configuration.
- Select VLD specific Build Configuration for development purposes.
References
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
本文介绍如何使用Visual Leak Detector (VLD)在Visual C++应用程序中检测内存泄漏。通过简单地在项目中包含vld.h头文件,VLD可以在调试会话结束时报告代码段中的内存泄漏位置,精确到分配泄漏内存块的确切代码位置。
660

被折叠的 条评论
为什么被折叠?



