tags:

views:

55

answers:

2

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
Thanks, I thought that was how it worked, just needed to make sure since I couldn't find any info in MSDN.
joek1975
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