Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What unnamed GDI resources could I be leaking

I ran an overnight stress test of my application, and when i came in this morning the software had crashed from a Windows error.

The error occurred because the process was obviously out of GDI handles:

Process Explorer

enter image description here

Task Manager

enter image description here

The next thing is to figure out exactly which kind of GDI resource (e.g. Pen, Brush, Bitmap, Font, Region, DC) i'm leaking. For that i turned to NirSoft's GDIView:

enter image description here

  • Pen: 0
  • Ext Pen: 0
  • Brush: 4
  • Bitmap: 35
  • Font: 19
  • Palette: 1
  • Region: 3
  • DC: 11
  • Metafile DC: 0
  • Enhanced Metafile DC: 0
  • Other GDI: 0
  • GDI Total: 0
  • All GDI: 10,000

What could a GDI handle be, one that is not any known GDI type?

like image 206
Ian Boyd Avatar asked Dec 29 '16 15:12

Ian Boyd


People also ask

How do I know if my GDI is leaking?

You can usually spot this issue, besides your applications crashing, by opening up the Task Manager, going to the Details tab, right click the columns, and click “Select Columns”. From this list you should be able to choose GDI objects and view them in the new column.

What is GDI objects in Task Manager?

The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers.

What is GDI View software?

GDIView is a unique tool that displays the list of GDI handles (brushes, pens, fonts, bitmaps, and others) opened by every process. It displays the total count for each type of GDI handle, as well as detailed information about each handle.


1 Answers

The answer was GDI HFONT handles.

It is a Windows 8 issue that GDIView cannot show the font handles.

I used hooking to intercept every call to:

  • CreateFont
  • DestroyFont

and logged every handle creation, along with its stack trace of when it was allowed. At the end i created a report of all undeleted HFONTs.

like image 52
Ian Boyd Avatar answered Oct 28 '22 22:10

Ian Boyd