PC Review


Reply
Thread Tools Rate Thread

Dispose questions

 
 
Lance
Guest
Posts: n/a
 
      7th Dec 2003
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.Clip.Dispose 'Is there any advantage to this line?
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


Thanks!
Lance
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      7th Dec 2003
"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

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Dec 2003
* "Lance" <(E-Mail Removed)> scripsit:
> 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.Clip.Dispose 'Is there any advantage to this line?
> g.Clip = New Drawing.Region(rect)


AFAIS you will have to dispose this region.

> 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


This depends on where the objects come from. If the caller disposes the
objects, you dont need/should not dispose them in the procedure.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Lance
Guest
Posts: n/a
 
      7th Dec 2003
Thanks to both people who replied!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphics object and dispose() - some questions?? juvi Microsoft Dot NET Compact Framework 0 1st Feb 2009 11:06 AM
Few difficult for me questions about Dispose() Piotrekk Microsoft C# .NET 13 11th Feb 2008 05:35 PM
Dispose questions JS Microsoft Dot NET Framework Forms 1 14th Feb 2007 11:58 AM
Questions about Dispose() TheSteph Microsoft C# .NET 3 7th Jun 2006 06:23 PM
GC and Dispose method questions =?Utf-8?B?VGVyZXNh?= Microsoft VB .NET 6 14th Jan 2005 12:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:56 PM.