473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dispose and Finalize

Dear all,
can somebody explain difference between Dispose and Finalize and when each
of them should be used?
Thank you very much,
Boni
Nov 21 '05 #1
3 1934
Hello Boni,

You have five articles in MSDN beginning with this:
Finalize Methods and Destructors:
http://msdn.microsoft.com/library/?u...asp?frame=true
In resume, it says:
Your class should have a Finalize method if it holds unmanaged resources.
Your class should implement IDisposable if it has a Finalize method or if it holds objects that hold unmanaged or expensive resources themselves.

The recommended general aspect of these methods is the following:

Implements IDisposable

'Leave this method as is:
Public Overloads Sub Dispose()Implements IDisposable.Dispose
Dispose(true)
GC.SuppressFinalize(Me) 'Only if the Finalize method exists.
End Sub

'Modify conveniently this method:
Protected Overloads Overridable Sub Dispose(disposing As Boolean)
If (disposing) Then
' Dispose managed resources (like managed files, managed graphic objects, ...).
End If
' Release unmanaged resources (like Windows handles to files, to windows, ...).
End Sub
'Leave this method as is:
Protected Overrides Sub Finalize()
Dispose(false)
End Sub

You must take into account things like thread safety and multiple calls to Dispose, but in general that's all.

Regards.
"Boni" <oilia@nospam> escribió en el mensaje news:uC**************@TK2MSFTNGP12.phx.gbl...
| Dear all,
| can somebody explain difference between Dispose and Finalize and when each
| of them should be used?
| Thank you very much,
| Boni

Nov 21 '05 #2
Does anyone know if this applies to the MSHTML class usage in VB.net which I
believe is accessed a COM interface? If so what all needs to be finalized
and destroyed?

Thanks,
Curtis

"José Manuel Agüero" <jmaguero_vodafone.es> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hello Boni,

You have five articles in MSDN beginning with this:
Finalize Methods and Destructors:
http://msdn.microsoft.com/library/?u...asp?frame=true

Nov 21 '05 #3
Curtis,
Does anyone know if this applies to the MSHTML class usage in VB.net which
I believe is accessed a COM interface? If so what all needs to be
finalized and destroyed?

Do you not mixing this up with the AxWebBrowser. Although I have put it as
well in a component. Than the complete Idisposable code is created for you.
The same as on a form. Open the designer created code for that.

I hope this helps,

Cor
Nov 21 '05 #4

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

Similar topics

8
by: celeong | last post by:
Hi, anybody can help me with this. I've created a singleton class, and now wants to add destructor to it. I know we can implement the IDisposable and also overrides the Finalize method (from...
4
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...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
4
by: Sunit Joshi | last post by:
Hello All I have an abstract class C1 with this: public abstract class C1 { protected bool m_Dirty; protected override void Dispose(bool disposing) { if(m_Dirty) WriteOuput();
4
by: Joe Abou Jaoude | last post by:
I m preparing to pass the 70-306 exam, so i downloaded Q & A from multiple sites. There's this question that really confuses me, coz i see that both answers A and C are both correct. Can anyone...
6
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...
156
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...
2
by: eBob.com | last post by:
I have a user control which creates an Excel spread sheet and badly needs Dispose/Finalize. I've read up on the subject in Balena and I think I understand what is going on. But the VS generated...
4
by: BLUE | last post by:
I've read many articles including the one from Duff's blog but I've many doubts. public static myClass Instance { get { if (myClass.instance == null) myClass.instance = new myClass();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.