Hi all , May i know should I set an object to nothing even after implementing an IDisposable method to my custom class ? Correct me if i am wrong , if you set it to nothing you are just setting the object to its default value . As you might risk losing a body of references which the GC cant be able to trace later on .

Class TestObject
   Implements IDisposable

    ' Implement IDisposable.
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
    End Sub

   Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)

        If disposing Then
        End If
   End Sub

     Protected Overrides Sub Finalize()
    End Sub

End Class
Dim x as new TestObject


x = Nothing
6 Years
Discussion Span
Last Post by thines01

I assume you meant like the following

Dim x as string = "Test"

x = nothing

By doing the above , you are just setting the x to its default type value and removing the x (string)'s pointer to the data "test" null .

I want to know is it feasible to set custom objects with filled properties to null. Does setting it to nothing , assist GC in any way ? From what i understand , it only removes the references of the data and makes it harder to trace for the GC. Please correct me i am wrong in anyway . =)

Edited by shadachi: n/a


Well, Nothing is the default value of a String, which is different than an empty string.

But I understand what you are asking.
From what I know, (after setting the object to a value) it's no better or worse than setting it to a new value.
It would create a new (Nothing) object and the old one is available for GC.

I would then imagine the bodiless reference to the new (null/Nothing) object is removed when it goes out of scope or no longer has any references.

So, it would not be better to set it to Nothing in order to "help" it be GC'd.

Edited by thines01: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.