Object Lifetime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a function that instanciates an object like this...

Private Sub MySub()
Dim myObject as new myClass
End Sub

My new object has a timer that fires every min waiting for some criteria to be satified. Once the criteria is satisfied how can myObject destroy itself?
 
Jeff Grundy said:
I have a function that instanciates an object like this...

Private Sub MySub()
Dim myObject as new myClass
End Sub

My new object has a timer that fires every min waiting for some
criteria to be satified. Once the criteria is satisfied how can
myObject destroy itself?

As soon as there are no more live references to it, the object will be
eligible for garbage collection. When it's actually collected is
another matter, however.
 
Hi Jeff

You'll need to make sure there is a live reference to your object to ensure it is not collected, unless you've implemented the timer with a Thread, since Threads are considered
GC roots, and are not collected until they are stopped and the reference lost.

Hope that helps
-Chris

--------------------
 
Back
Top