Quick question - if I create a timer and it can be ‘.rescheduled’, then when does it get cleaned up?
The ‘.isrunning’ method implies the timer object is hanging around after the timer has triggered. So in the code below, is my code consuming memory by creating lots of timer objects that never get cleaned up?
var Timer MyTimerObj = null
rule “Delay Timer”
when
… some trigger …
then
if (MyTimerObj !== null && MyTimerObj.isRunning)
MyTimerObj.cancel()
MyTimerObj = createTimer(now.plusSeconds(delay_period)) [
// do some stuff when the timer goes off
]
end
To be fair, the MyTimerObj variable is only a “handle”, a pointer to the timer.
It’s pretty easy to make a demo where creating a second timer assigned to the same handle does not destroy or overwrite the first timer. You just can’t get hold of it anymore, to cancel/reschedule/etc.
I don’t know how the garbage collection works, but can see there will be timers that no longer have external references. i.e. there is neither any actual schedule (it’s been run or cancelled) nor is there a extant handle (it’s been null or overwritten).
If the garbage collector can work that out, it can sweep up that timer code.
Hi Rossko57 - I did there same as you and created a few tests to see what I could do with timer pointers. It looks like they continue to exist for a while at least. You can cancel the timer and then reschedule, but I suspect I’m rescheduling a stale timer object before it’s cleaned up
I imagine the objects are small, so it would take a long time to chew up memory.