How to Dispose any class obj

sanjughelani

Newcomer
Joined
Sep 4, 2003
Messages
1
How to set nothing, any of the class from Form. I’m using the class object multiple times with different instances.
eg;
Sub txtName_Enter()
if not clsNew is Nothing then clsNew = Nothing
clsNew = New MyClass
clsNew.Start
End Sub

Sub txtCustomer_Enter()
if not clsNew is Nothing then clsNew = Nothing
clsNew = New MyClass
clsNew.Start
End Sub
 
Because of the way managed code works, you don't need to set clsNew = Nothing before creating a new one. You can call clsNew.Dispose() (if your class implements IDisposable) to dispose of the object, but the class will be disposed of as soon as there is no reference to it anyway. You can simply use clsNew = New MyClass to set a new instance, and the framework will handle the disposition itself.
 
Back
Top