Do I always need to Dispose a Graphics objectÇ

J

Juan Dent

Hi,

I understand that if one creates a Graphics object, as in
Graphics.FromImage(), then after using it it seems only logical do dispose it.

However, when one receives a Graphics object in a parameter (as in OnPaint(
PaintEventArgs)), then I assume it might be possible that this object be used
after the end of the current method, andçor ultimately disposed by the
internall code that created it in the first place. So, my gut tells me not to
Dispose this received Graphics.


Am I correct?
 
P

Peter Duniho

[...]
However, when one receives a Graphics object in a parameter (as in
OnPaint(
PaintEventArgs)), then I assume it might be possible that this object be
used
after the end of the current method, andçor ultimately disposed by the
internall code that created it in the first place. So, my gut tells me
not to
Dispose this received Graphics.

Right. Don't dispose things you don't own. You only own it if either you
created it, or the whatever did create it has explicitly handed ownership
to you.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top