call dispose on every graphics object or just 'Graphics' object?
Do I need to also do:
bitmap.dispose();
Brush.dispose();
brush2.dispose();
Or will it be sufficient to just do开发者_开发问答:
graphics.dispose();
In short; you should call Dispose
on all instances that you create of types that implement IDisposable
. So, if you create a Graphics
object, and a Brush
to draw on it, both should be diposed.
One example of what not to dispose, is the graphics object that is passed into OnPaint
methods. This instance is created by the framework, and may be passed to several other method calls. Also the brushes found in Brushes
and SystemBrushes
and the pens found in Pens
and SystemPens
are shared and should (and could) not be disposed by your code.
精彩评论