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