vs2019使用vld檢測內存泄漏


引言

在windows平台下,一個檢測內存泄漏的工具是vld。
下載地址是:https://kinddragon.github.io/vld/
github地址:https://github.com/KindDragon/vld

使用

從網上下載exe安裝包。安裝過程中,可以選擇把vld頭文件、lib、dll安裝在系統環境下。
安裝完成之后,默認在C:\Program Files (x86)\Visual Leak Detector目錄有頭文件和x86、x64平台debug版本的庫。vld只能在debug模式下使用。
然后,在項目中包含vld.h頭文件。
當前,vld最高支持到vs2015,在vs2019默認沒有提示泄漏出現在哪一行。我們可以在屬性設置中做相關配置即可,如下圖:

配置

默認使用安裝目錄下的vld.ini配置文件。我們可以把該文件放在運行程序同一個目錄下,修改這個文件。
比如,我們可以指定將輸出信息保存到文件中,同時打印在屏幕上,然后配置文件的路徑:

; Sets the report file destination, if reporting to file is enabled. A relative
; path may be specified and is considered relative to the process' working
; directory.
;
;   Valid Values: Any valid path and filename.
;   Default: .\memory_leak_report.txt
;
ReportFile = .\memory_leak_report.txt

; Sets the report destination to either a file, the debugger, or both. If
; reporting to file is enabled, the report is sent to the file specified by the
; ReportFile option.
;
;   Valid Values: debugger, file, both
;   Default: debugger
;
ReportTo = both

示例

如下一段代碼:

#include <iostream>
#include <vld.h>

int main()
{
	int* a = new int[20];

	return 0;
}

運行結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM