如何捕獲(並希望修復)GDI 資源洩漏 (How to catch (and hopefully fix) a GDI resource leak)


問題描述

如何捕獲(並希望修復)GDI 資源洩漏 (How to catch (and hopefully fix) a GDI resource leak)

My application logs an exception after running for 6 hours:

OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3 (5.1.2600.196608)

.NET Version: 2.0.50727.3082

SQL Server Version:  9.00.4035.00

SQL Server Level:  SP3

SQL Server Edition:  Standard Edition

Error Message: Parameter is not valid.

Exception type: System.ArgumentException

Source:  System.Drawing

Stack Trace: 
at System.Drawing.Graphics.GetHdc()
at System.Windows.Forms.ImageList.GetBitmap(Int32 index)
at System.Windows.Forms.ImageList.ImageCollection.get_Item(Int32 index)
<<< MY code >>>

‑‑‑‑‑

參考解法

方法 1:

Recently I've created a simple class that calls GetGuiResources() function in both the constructor and destructor and reports any differences in GDI object counts. Using it as a scoped object in a few functions helped me plug GDI leaks in the code.

方法 2:

GDIView worked for me.  It pointed to a Font leak.  I did a search for ToHfont().  The rest is history.

(by GregCmacbirdieGregC)

參考文件

  1. How to catch (and hopefully fix) a GDI resource leak (CC BY‑SA 3.0/4.0)

#gdi #user-interface #memory-leaks #C# #resources






相關問題

繪製鼠標光標 (Draw mouse cursor)

C 和 Windows GDI 中的雙緩衝 *framework* (Double-buffering *framework* in C and Windows GDI)

一個進程的 GDI 洩漏會影響其他進程嗎? (Can GDI leaks from one process affect other processes?)

BeginPath Textout EndPath 繪製反轉文本 (BeginPath Textout EndPath draws inverted text)

監控GDI通話 (Monitoring GDI calls)

如何捕獲(並希望修復)GDI 資源洩漏 (How to catch (and hopefully fix) a GDI resource leak)

如何使用 GDI(+) 在內存中渲染漸變 (How to render a gradient in memory using GDI(+))

使用 BITMAP::bmBits 與 GetDIBits 有什麼區別? (What is the difference between using BITMAP::bmBits vs GetDIBits?)

獲取背景窗口的縮略圖 (Get Thumbnail of background window)

AlphaBlend 返回“假”的原因可能是什麼 (What could be the reason for AlphaBlend to return 'false')

在 C++ 中查找像素 RGB 數據的最快方法是什麼? (What is the fastest method to lookup pixel RGB data in C++?)

逐行讀取文本框並將其視為單獨的文本 (Read a textbox line by line and treat it as a separate text)







留言討論