At 15:29 +1100 01_02_20, Luke Wigley wrote:
>A barebones version of the script looks like
>this
>
>property mytimeoutName
>property myCounter
>
>on new (me)
>   myCounter = 0
>   mytimeoutName = me.string&&"thread"
>   timeout(mytimeoutName).new(100, #mProcessThread, me)
>end
>
>on mProcessThread (me)
>   if myCounter < 10 then
>     myCounter = myCounter + 1
>     put myCounter
>   else
>     -- finished doing its thing
>     timeout(mytimeoutName).forget()
>   end if
>end

A small detail here, is that timeout_objects actually send their own 
reference when making callbacks to their target, so you don't need to 
store any reference to them, string or directly.

I would also believe that forgetting the timeout_object would remove 
the last reference to, and thus garbage collect the target object.
I noticed that forgetting the timeout_object did not immediately 
lower the refCount of the target object, so the actual destruction of 
the timeout_object is probably deferred to later. However one can 
just force the refCount down, by voiding the timeout_object.target 
and then there is doubt about the refCount.

property myCounter

on new (me)
   myCounter = 0
   timeout(me&&"thread").new(100, #mProcessThread, me)
end

on mProcessThread (me, aTimer)
   myCounter = myCounter + 1
   if myCounter > 9 then
     aTimer.target = VOID
     aTimer.forget()
   end if
   put myCounter
end


Re. circular ref:
remember that it takes only one object to create a circular 
reference, if the object stores a reference to itself. So if your 
target object is self-referencing, forgetting the timeout_object wont 
destroy the target object.


Regards, Jakob

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to