"Disposing" of graphics objects?

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
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
 
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
 
* "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.
 
Back
Top