By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,642 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,642 IT Pros & Developers. It's quick & easy.

Dispose and Finalize

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.