Avoiding disposing system-defined Pen and Brush instances

后端 未结 8 2011
离开以前
离开以前 2021-02-14 01:07

I understand it is best practise to call Dispose() on instances of Pen and Brush, except if they\'ve been set to the system-predefined values (eg. System.Drawing.Brushes, Syste

8条回答
  •  日久生厌
    2021-02-14 01:46

    Just for completeness, using Reflector I see that the System.Drawing.Pen and System.Drawing.SolidBrush classes have a private field named 'immutable'.

    This field appears to be set to true when the object refers to a system-defined resource, so you could use reflection to carefully check the value of this field to decide whether to call Dispose() on it.

提交回复
热议问题