473,511 Members | 14,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dispose questions

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
Nov 20 '05 #1
3 1060
* "Lance" <zi***@hotmail.com> 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>
Nov 20 '05 #2
"Lance" <zi***@hotmail.com> 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

Nov 20 '05 #3
Thanks to both people who replied!
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1902
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or...
11
5263
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
16
4232
by: Daniel Mori | last post by:
If an object implements the IDisposable interface (regardless if its a framework object or a user object), should I always dispose of that object out of principle?
6
1818
by: Cody Powell | last post by:
Greetings all, I'm wondering if there's a rule of thumb related to objects that implement IDisposable, but whose Dispose() methods are actually marked as protected. If you dig around System.IO,...
6
1784
by: Teresa | last post by:
1) If I do want to keep an object alive throughout the live of an application, how can I ensure that the GC doesn't clean it up? 2a) How do I determine if an object is a managed or an unmanged...
14
1876
by: Jonas | last post by:
Hi! I'm developing the middletiers of an ASP.NET application in VB.NET. I've got a business logic layer in which I would like to perform auditing to a database. Instead of making an auditing...
156
5736
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
9
1693
by: Geoff Callaghan | last post by:
I have several functions that require doing a New on a local object. If the object is local to a sub or function, do I need to dispose of it, or will it just go away like any other local variable?...
0
3190
by: Jeff | last post by:
Banging my head against the wall trying to figure this out. I have a 'sometimes' hang while disposing a form which contains an ActiveX control (Flash.ocx version 7). The form's Dispose() method...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.