Do I need to call Dispose() on managed objects?

后端 未结 11 1867
忘了有多久
忘了有多久 2020-12-08 14:51

I can\'t believe I\'m still confused about this but, any way, lets finally nail it:

I have a class that overrides OnPaint to do some drawing. To speed things up, I c

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 15:16

    No, Pens and Brushes are not fully managed objects.

    They contain a handle to an unmanaged resource, i.e. the corresponding GDI object in the underlying graphics system. (Not certain about the exact terminology here...)

    If you don't dispose them, the handles will not be released until the objects are finalised by the garbage collector, and there is no guarantee that it will happen soon, or at all.

提交回复
热议问题