說明
使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記,本篇介紹 VLD 組態檔中配置項 SelfTest 的使用方法, 同系列文章目錄可見 《記憶體泄漏檢測工具》目錄
目錄- 說明
- 1. 組態檔使用說明
- 2. 設定是否開啟泄漏自檢
- 2.1 測驗代碼
- 2.2 SelfTest = off 時的輸出
- 2.3 SelfTest = on 時的輸出
- 2.4 輸出結果對比
1. 組態檔使用說明
在程式中通過 #include "vld.h" 的方式檢測記憶體泄漏時,VLD 首先會嘗試在程式的生成目錄下讀取 vld.ini 檔案,若未讀取成功,則會嘗試在 VLD 的安裝目錄下讀取 vld.ini 檔案,若仍未讀取成功,則會使用內置的默認配置,內置的默認配置如果不動原始碼是無法更改的,因此通過修改相應目錄下的 vld.ini 檔案來定制 VLD 功能是最好的選擇,當配置引數等號右邊為空,或者給配置了不合法值時,在使用程序中會被程式重置到默認值,
2. 設定是否開啟泄漏自檢
引數名:SelfTest,
有效賦值:on,off,
默認值:off,
功能說明:打開或關閉自檢模式,每次使用 VLD 時,除了檢查需檢測的程式是否有記憶體泄漏外,它也在檢查自己是否有記憶體泄漏,將這個選項設定為 on 時,VLD 會有意地泄漏少量記憶體:一塊大小為 22 bytes 的記憶體,填充內容為 'Memory Leak Self-Test' 這個長度為 21 的字串,這個配置項提供了一種方法來測驗 VLD 檢查自身記憶體泄漏的能力,并驗證該能力是否正常作業,這個配置項只對除錯 VLD 自身有用,
2.1 測驗代碼
#include <QCoreApplication>
#include "vld.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
測驗環境:QT 5.9.2,MSVC 2015 32bit,Debug 模式,VLD 版本為 2.5.1,VLD 組態檔只對該引數做修改,測驗工程所在路徑為:E:\Cworkspace\Qt 5.9\QtDemo\testVLD,
2.2 SelfTest = off 時的輸出
VLD 輸出報告:
Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
No memory leaks detected.
Visual Leak Detector is now exiting.
2.3 SelfTest = on 時的輸出
VLD 輸出報告:
Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
Performing a memory leak self-test.
No memory leaks detected.
Visual Leak Detector is now exiting.
ERROR: Visual Leak Detector: Detected a memory leak internal to Visual Leak Detector!!
---------- Block 6 at 0x01430810: 22 bytes ----------
Call Stack:
vld.cpp (439): Full call stack not available.
Data:
4D 65 6D 6F 72 79 20 4C 65 61 6B 20 53 65 6C 66 Memory.L eak.Self
2D 54 65 73 74 00 -Test... ........
Visual Leak Detector passed the memory leak self-test.
2.4 輸出結果對比
- 當
SelfTest = off時 VLD 沒有故意泄漏記憶體, - 當
SelfTest = on時 VLD 故意泄漏了一塊22 bytes的記憶體用于展示自檢功能,同時沒有影響到正常的檢測功能,
本文作者:木三百川
本文鏈接:https://www.cnblogs.com/young520/p/17263212.html
著作權宣告:本文系博主原創文章,著作權歸作者所有,商業轉載請聯系作者獲得授權,非商業轉載請附上出處鏈接,遵循 署名-非商業性使用-相同方式共享 4.0 國際版 (CC BY-NC-SA 4.0) 著作權協議,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/548473.html
標籤:其他
上一篇:【Visual Leak Detector】配置項 ReportTo
下一篇:架構的演進
