"Lance" <(E-Mail Removed)> schrieb
> I have a couple of dispose questions.
>
> 1. Is it advantageous to dispose Drawing.Graphics.Clip
> before setting a new clip region? Here is an example:
>
> Dim rect As New Drawing.Rectangle(10, 10, 20, 20)
> Dim g As New Drawing.Graphics
"g As New Drawing.Graphics" does not work because there is no public
constructor.
> g.Clip.Dispose 'Is there any advantage to this line?
Yes, the native region is destroyed immediatelly. Otherwise it won't be
destroyed before the region is collected and finilized by the GC.
> g.Clip = New Drawing.Region(rect)
>
>
> 2. Is it necessary to dispose objects that are only
> passed as parameters? Here is an example (please ignore
> the fact that you could just use Graphics.FillRectangle in
> this example):
>
> Sub DrawRectUsingARegion(ByVal g As Drawing.Graphics,
> ByVal rect As Drawing.Rectangle)
> 'Can you do the following?
> g.FillRegion(New Drawing.Region(rect))
> 'Or, should you do this?
> Dim rgn As New Drawing.Region(rect)
> g.FillRegion(rgn)
> rgn.Dispose
> End Sub
I'd choose the 2nd way for the same reason given above.
--
Armin
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html