Best strategy for living a GDI + object?

In our application, we have several GDI + objects that are often used in many different contexts. This includes some examples Font, SolidBrush(white, black ...), some Pen...

For these objects, our strategy so far has been to hold them through read-only static visible fields. This allows you to create or delete them millions of times. We took care of access to the security stream on this object, of course (they are simply accessible from the user interface stream basically).

There are only a few of these GDI + objects for the life of the application, for example, 200. The rest of the GDI + objects (those with a short lifespan) are all located as soon as possible. But we sometime receive an unexpected exception from failures of GDI + resources, I hope, seldom enough.

I am wondering if these exceptions can come from these few GDI + objects, and if this were a more reasonable strategy for creating / deleting tons of GDI + objects with a short validity period. Does anyone have real experience and relevant conclusions about the two strategies?

+4
source share
1 answer

System.Drawing . , . , . 65535 . , , , , . , , - . , . .NET, .

, , . . , , , , . , GC, GDI. 10 000 . . , System.Drawing , GC , 10000 .

, . View + Select Columns "GDI Objects". "USER Objects", , . , . .

+11

Source: https://habr.com/ru/post/1534663/


All Articles