Jakob Hede Madsen wrote

> 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.

Hi Jakob,
thanks for pointing that out - I never realised they pass their own
reference when making a callback.

> 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.

Yes, the refcount doesn't immediately lower - nor do the freebytes
immediately increase when my object (with its large image references) get
de-referenced - which is what got me wondering about whether the timeout
object hangs on to the reference even after it has been forgotten. But it
hadn't occurred to me to void the timeout's target (thanks to both Jacob &
Mark for that). Voiding the timeout target does seem the ensure that the
target obejct does get de-referenced.

This is a variation on the utility object- basically its the same as the one
I described earlier, except this one keeps a reference to an object it needs
to send a message to when the process has finished.

property myCallBackMsg  -- symbol
property myCallBackObj  -- object reference
property myTaskID       -- symbol or integer
 
on new (me, callbackMethod, callBackObj, taskID, processRate)
  myCallBackMsg = callbackMethod
  myCallBackObj = callBackObj
  myTaskID = taskID
  timeout( me.string&&"thread").new(processRate, #mProcessThread, me)
end

on mProcessThread (me, aTimer)
  -- doStuff
  if SomeEndConditionReached() then
    if objectP(myCallBackObj) then
      call(myCallBackMsg, myCallBackObj, myTaskID)
    end if
    -- myCallBackObj = VOID <-- not needed if void timeout target
    aTimer.target = VOID
    aTimer.forget()
  end if
end 

If I don't void the timeout's target, then the refcount to the callback
object doesn't decrease when the thread finishes unless I explicitly void
the reference to the callback object in the timed object. However, if I do
void the timout target, then the reference count to the callback object does
decrease when the thread finishes without explicitly voiding the reference
to the call back object - which I guess indicates that the object referenced
by a timeout is getting destroyed properly when the timeout's target is
voided, but not when the timeout is just simply forgotten (which is probably
a bug/Director quirk)



Luke






[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