In our application we have a few GDI+ objects that are used often in many different contexts. This includes some instances of Font
, SolidBrush
(White, Black...), some Pen
...
For those objects our strategy so far has been to hold them through widely visible static read-only fields. This avoids to create/dispose them millions of time. We took care of thread-safety accesses on these object of course (they are just accessed from the UI thread basically).
There are just a few of these GDI+ objects hold for the lifetime of the application, say like 200. The others GDI+ objects (the ones with short-life) are all disposed asap. But we sometime get unexpected GDI+ resources outage exception, hopefully rarely enough.
I am wondering if these exceptions could come from these few GDI+ objects hold, and if this would be a wiser strategy to create/dispose tons of short-life GDI+ objects instead. Does anybody have real-world experience and relevant conclusions about theses two strategies?