内存泄漏检

http://vld.codeplex.com/wikipage?title=Using%20Visual%20Leak%20Detector&referringTitle=Documentation


Using Visual Leak Detector


This section briefly describes the basics of using Visual Leak Detector (VLD).

Important! : Before using VLD with any Visual C++ project, you must first add the Visual Leak Detector include and library directories to the Visual C++ include and library directory search paths:
For all compiler versions take care to ensure that no junk characters get added when you add the include and library paths. If you browse to the "Program Files(x86) folder using the dialog box provided by Visual Studio and select it you could end up seeing the "%" replacing the "(". 

And remember to close and open the Visual Studio IDE once you have modified the default include and library paths which the compiler and linker would always look at.
  • Visual C++ 2010/2012/2013: Go to View ->Property Manager, select Microsoft.Cpp.Win32.user. SelectVC++ Directories and then "Include files" from the tree. Add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select "Library files" from the drop-down menu and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list. Repeat for Microsoft.Cpp.x64.user, but select lib\Win64subdirectory instead.
  • Visual C++ 2005 and 2008: Go to Tools -> Options -> Projects and Solutions -> VC++ Directories. Select"Include files" from the "Show Directories For" drop-down menu. Add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select "Library files"from the drop-down menu and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list.
  • Visual C++ 2003: Go to Project Properties -> C/C++ -> General -> Additional Include Directories and add the include subdirectory from the Visual Leak Detector installation directory. Move it to the bottom of the list. Then select Additional Library Directories and add the lib\Win32 subdirectory from the Visual Leak Detector installation directory. Again, move it to the bottom of the list.


To use VLD with your project, follow these simple steps:
  1. In at least one C/C++ source file from your program, include the vld.h header file. It should not matter which file you add the include statement to. It also should not matter in what order the header is included in relation to other headers. The only exception is stdafx.h (or any other precompiled header). A precompiled header, such as stdafx.h, must always be the first header included in a source file, so vld.hmust be included after any precompiled headers.
  2. If your program contains one or more DLLs that you would also like to check for memory leaks, then also include vld.h in at least one source file from each DLL to be included in leak detection.
  3. Build the debug version of your program.

Note: Unlike earlier (pre-1.9) versions of VLD, it is now acceptable to include  vld.h in every source file, or to include it in a common header that is included by many or all source files. Only one copy of the VLD code will be loaded into the process, regardless of how many source files include  vld.h.
VLD will detect memory leaks in your program whenever you run the debug version. When you run the program under the Visual C++ debugger, a report of all the memory leaks detected will be displayed in the debugger's output window when your program exits (the report can optionally be saved to a file instead, see ReportFile under  Configuration Options). Double-clicking on a source file's line number in the memory leak report will take you to that file and line in the editor window, allowing easy navigation of the code path leading up to the allocation that resulted in the memory leak.

Note: When you build release versions of your program, VLD will not be linked into the executable. So it is safe to leave  vld.h included in your source files when doing release builds. Doing so will not result in any performance degradation or any other undesirable overhead.

Last edited Dec 26, 2013 at 1:20 AM by KindDragon, version 7


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
内存分析和内存泄漏定位是软件开发中非常重要的技能,它们可以帮助我们识别和解决应用程序中的内存问题。 内存分析是指通过检查应用程序中的内存使用情况来识别内存问题。通常,内存分析工具会提供有关内存分配情况、内存使用情况和内存泄漏情况的详细信息。这些工具还可以帮助开发人员识别内存分配的位置、内存使用的模式以及内存泄漏的原因。 内存泄漏定位是指通过分析应用程序的内存使用情况来确定内存泄漏的位置和原因。通常,开发人员可以使用内存分析工具来识别内存泄漏的位置和原因。然后,他们可以采取必要的措施来修复内存泄漏问题,例如释放未使用的内存、修改代码以减少内存使用等等。 在进行内存分析和内存泄漏定位时,开发人员应该注意以下几点: 1. 了解应用程序的内存使用模式和内存分配情况。 2. 使用合适的内存分析工具来识别内存泄漏问题,例如Valgrind、GDB等。 3. 识别内存泄漏的位置和原因,并采取必要的措施来修复内存泄漏问题。 4. 对于大型的应用程序,可以考虑使用自动化的内存分析和内存泄漏定位工具,例如Heaptrack、Memcheck等。 总之,内存分析和内存泄漏定位是软件开发中非常重要的技能。通过学习这些技能,开发人员可以更好地识别和解决应用程序中的内存问题,提高应用程序的性能和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值