How do I know if I have an unmanaged resource?
Posted
by Shiftbit
on Stack Overflow
See other posts from Stack Overflow
or by Shiftbit
Published on 2010-06-01T22:49:29Z
Indexed on
2010/06/01
23:03 UTC
Read the original article
Hit count: 491
I've read that unmanaged resource are considered file handles, streams, anything low level. Does MSDN or any other source explain how to recognize an unmanaged resource? I can't seem to find any examples on the net that show unmanaged code, all the examples just have comments that say unmanaged code here.
- Can someone perhaps provide a realworld example where I would handle an unmanaged resources in an IDispose interface? I provided the IDisposable interface for your convience.
- How do I identify an unmanaged resource?
Thanks in advance!
IDisposable Reference
Public Class Sample : Implements IDisposable
Private disposedValue As Boolean = False 'To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free other state (managed objects).
End If
' TODO: free your own state (unmanaged objects).
' TODO: set large fields to null.
End If
Me.disposedValue = True
End Sub
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class
© Stack Overflow or respective owner