-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Prasanna_kakanoor
Message 2 in Discussion

Hi, 

Finalize = implicit, as such it will only come into being when the
Garbage collector runs.
Dispose = Explicit, YOU have control, this will release 'object
references' immd. that the Garbage collector can clear on its next run.

Sample question:

You develop a windows based application MyApp by using Visual
Studio.NET. MyApp uses a SQLConnection Object to access a
database.
Your client computers that will run MyApp have limited resources.After
MyApp finishes using the SQLConnection object you must ensure that the
connection is closed and all resources used by the object are released
immediately.

What should you do?

The question asks us to release resources immd. the only way we can
achieve this and have control would be to

Public Sub SqlConnectionNowYouSeeItNowYouDont()
Dim myConnection As New SqlConnection()
myConnection.Open()
'Calling Dispose also calls OleDbConnection.Close.
myConnection.Dispose()
End Sub

If we used finalize() we would only be marking the object for Garbage
Collection, and as we do not really have control when GC will run it
will not release resources immd.
Finalize method invokes Dispose, and also has a higher cost than
Dispose.

So one way to "think" of it is :

Finalize() is like putting your trash in a trash can, when the can is
full, "someone" will have to bag it, "someone" will have to take the
trash to the outside bin, then on trash day "someone" will have to put
the bin out on the driveway for the garbage collectors. (we are passing
responsibility for our trash to others, and what if we forget what day
to put the trash out it starts cluttering up the place etc,etc)

Dispose() we will bag the trash RIGHT NOW.,we will put the trash in the
outside bin on the drive RIGHT NOW for the garbage collectors. We dont
care when the garbage collectors come, we just dont want the trash on
our property!

HTH and I havent confused you too much.


Regards,
Prasanna K L [MCAD(CM) | MCSD.NET(Early Achiever)] [MS Community Star]

|Sr. Software Engineer�|First American Interactive Division|Office:+91 80�5115 6050  
Extn 4084 |Mobile:+91 98452 76356�|Fax:+91 80�841 1858 |[EMAIL PROTECTED] |
|Unit 1, Level 1, Explorer Building, International TechPark, Whitefield Road, 
Bangalore-560066|India| Website: www.firstam.com |

-----Original Message-----
From: Mamatha_md [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 11, 2003 12:04 PM
To: BDOTNET
Subject: Dispose Vs Finalize



New Message on BDOTNET


Dispose Vs Finalize
Reply

�
Reply to Sender ��Recommend 
Message 1 in Discussion 

From: Mamatha_md 

Hi all,
�
What is the difference between dispose and finalize??
How to choose between them?
�
Thanks,
Mamatha


View other groups in this category. 


Also on MSN:
Start Chatting�|�Listen to Music�|�House & Home�|�Try Online Dating�|�Daily Horoscopes 

Passport Member Services. 
For other questions or feedback, go to our Contact Us page. 

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list. 
Remove my e-mail address from BDOTNET. 



-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to