G
Guest
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 resource? I
understand the basic definition for managed resources are resources that the
CLR manage and unmanged resources are resources that the CLR doesn't manage,
however, I haven't been able to find a concrete answer as to what resources
are manage or not manage by the CLR.
2b) This is a following question to 2a. Are String and Int32 managed or
unmanaged resources (since it's not possible to do sTemp.dispose or
iTemp.dispose)? So does doing sTemp = Nothing or iTemp = Nothing release the
resource back to the memory?
3) I created serveral classes and I would like to be able to control when I
dispose it. I've found several articles regarding this topic and in each of
these discussion, the solution is exactly identical. Below is the sample from
the Microsoft MSDN website and is it true that all I need to do is customize
the code below in each of class? Is that the correct implementation?
Public Class Base
Implements IDisposable
' Implement IDisposable.
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub
Protected Overrides Sub Finalize()
' Simply call Dispose(False).
Dispose(False)
End Sub
End Class
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 resource? I
understand the basic definition for managed resources are resources that the
CLR manage and unmanged resources are resources that the CLR doesn't manage,
however, I haven't been able to find a concrete answer as to what resources
are manage or not manage by the CLR.
2b) This is a following question to 2a. Are String and Int32 managed or
unmanaged resources (since it's not possible to do sTemp.dispose or
iTemp.dispose)? So does doing sTemp = Nothing or iTemp = Nothing release the
resource back to the memory?
3) I created serveral classes and I would like to be able to control when I
dispose it. I've found several articles regarding this topic and in each of
these discussion, the solution is exactly identical. Below is the sample from
the Microsoft MSDN website and is it true that all I need to do is customize
the code below in each of class? Is that the correct implementation?
Public Class Base
Implements IDisposable
' Implement IDisposable.
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub
Protected Overrides Sub Finalize()
' Simply call Dispose(False).
Dispose(False)
End Sub
End Class