Groups | Blog | Home
all groups > visual studio .net general > march 2004 >

visual studio .net general : Declare a class in a routine hoping it will destroy itself at the end of it


marie mercier
3/4/2004 6:41:07 AM
Hi, here is my question. In vb6, I could declare a class in a form's private sub. At the end of that sub, the 'Terminate' event was called and my instantiation was destroyed. I notice now that no such event is called, and that a new class instantiation is made every time I call this sub routine.

AND I would like to clean up by calling method in my class....ALL IN ONE LINE OF CODE the idea being not having to worry about how the code exited from the subroutine

in my form:
private sub butSave_Click(....)
dim oHourGlass as new cHourGlass do stuff
end sub 'I want the class to be destroyed
------------------------------------------------------
cHourGlass class is like this

Public Sub New()
Cursor.Current = Cursors.WaitCursor
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
Cursor.Current = Cursors.Default
End Sub

Daniel Clausen
3/4/2004 3:36:07 PM
Marie
Garbage collection works a lot different in .Net. Previously in VB6 as soon as a object was no longer referenced it was cleaned up. In .Net a object is not cleaned up until it needs the memory space. If all your worried about is making sure that the object gets cleaned up it will in due time

For more info check out this section of the Framework Developer's Guide
marie mercier
3/5/2004 5:56:11 AM
AddThis Social Bookmark Button