How to catch (and hopefully fix) a GDI resource leak

My application logs an exception after working 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 >>> 
+4
source share
2 answers

I recently created a simple class that calls the GetGuiResources() function in both the constructor and the destructor and reports any differences in the GDI object to the account. Using it as an object with a scope in several functions helped me plug in the GDI leaks in the code.

+4
source

GDIView worked for me. He pointed to the leak of the Font. I performed a search for ToHfont (). The rest is history.

+2
source

All Articles