How to dispose a custom class object

Hi, I have a custom class who doesn't inherit any system component object.

How should I dispose an object of this class

My class does not inherit a dispose method, so how should I create one
I have read the dispose finalize pattern that suggests to use IDisposable. In this pattern we have managed resource.dispose method.

Protected Overridable Overloads Sub Dispose( _
            ByVal disposing As Boolean)
            If Not Me.disposed Then
                If disposing Then
                    managedResource.Dispose()
                End If
                ' Add code here to release the unmanaged resource.
                unmanagedResource = IntPtr.Zero
                ' Note that this is not thread safe.
            End If
            Me.disposed = True
        End Sub

In my case I have to write my own commands to destroy the object. So how do I destroy an object   Should I set all the properties to nothing Inside my class in can't say Me=nothing for example

So do I say to an object to destroy itself



Answer this question

How to dispose a custom class object

  • GoingGreyFast

    Dispose is intended to be used to release an unmanaged resource or another objects used by your class that have a Dispose method. It's not intended/needed to "destroy" the object itself. So unless your class uses unmanaged resources or disposable objects like a FileStream or a SqlConnection you don't need a Dispose method.
  • How to dispose a custom class object