"Disposing" of graphics objects?

R

Robin Tucker

Hi there,


Do I need to call "Dispose" on System.Drawing.Brush and System.Drawing.Pen
if I've created new ones? What if I'm using stock brushes and pens? Also,
do I need to explicitly call "Dispose" on Graphics too? In all cases in my
code, they are local variables anyway. Won't VB.NET dispose them
automatically when the function exits?

Thanks for any tips,




Robin
 
C

Cor Ligthert

Robin,

When IDisposable is implemented in a class, VBNet should dispose everything
(including all so called unmanaged resources), however you do not know when,
so is told that by the larger objects calling dispose does not harm that
much, just to force it to let it go a little bit faster.

Cor

"Robin Tucker
 
H

Herfried K. Wagner [MVP]

* "Robin Tucker said:
Do I need to call "Dispose" on System.Drawing.Brush and System.Drawing.Pen
if I've created new ones?
Yes.

What if I'm using stock brushes and pens?

You should not dispose these objects.
Also, do I need to explicitly call "Dispose" on Graphics too?

Yes, if you use 'CreateGraphics' or similar to /create/ such an object.
In side event handlers often a 'Graphics' object is supplied in
'e.Graphics'. You don't need to/should not dispose these objects.
code, they are local variables anyway. Won't VB.NET dispose them
automatically when the function exits?

The object will be disposed sooner or later, but there is no guarantee
when it will be disposed.
 

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