.NET: 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 22:53 UTC
Read the original article Hit count: 429

Filed under:
|
|

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.

  1. 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.
  2. 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

Related posts about .NET

Related posts about unmanaged