Setting an object variable to Nothing does not destroy the object
In Visual Basic 6.0, setting an object to Nothing immediately destroyed the object. In Visual Basic .NET, setting an object to Nothing marks the object for garbage collection, but the object is not immediately destroyed. This could cause problems if other portions of your code depend on the object being destroyed.
For example, if an object is set to Nothing inside a procedure and the next line of code creates an object of the same name, the first object may not yet be destroyed and a reference to the new object might incorrectly return the first object.
What to do next
- Review your code and search for additional references to this object.
- If necessary, call the Dispose method to destroy the object immediately:
' Visual Basic .NET Dim x As New Button x.Text = "Goodbye" x.Dispose()