Do I need to call Dispose() on a Graphics object obtained through PaintEventArgs in an OnPaint event?
+5
A:
No, the calling layer (the one who actually created the graphics object) is in charge of that. Also think about it, when you have other callees on the chain, you will dispose the object and they won't be able to use it.
Shay Erlichmen
2009-07-29 15:15:01
Thanks, I thought that was how it worked, just needed to make sure since I couldn't find any info in MSDN.
joek1975
2009-07-29 15:20:14
A:
In general, you should not dispose of Graphic objects which you receive as method parameters. But you should dispos of Graphics objects that you've created yourself (for example using the CreateGraphics
method).
Igor Brejc
2009-07-31 06:04:36