Timer and Transition objects, must I remove them all once created?

Hello,
 
I want to ask a simple question.
Must I remove all Timer and Transition objects once created?
 
I have a destructor like this:

local function onDestroy()     -- remove listeners     Obj:removeEventListener("tap", onTap) --// I can skip this line if Obj is removed elsewhere, right?     Runtime:removeEventListener( "enterFrame", mainLoop )     -- remove global variables     var = nil     -- dispose sound     for i = 1, #soundGroup do         audio.dispose(soundGroup[i])         soundGroup[i] = nil     end     -- remove transitions     for i=1, #transGroup do         if(transGroup[i]) then             transition.cancel(transGroup[i])             transGroup[i] = nil         end     end     --remove timers     for i=1, #timerGroup do         if(timerGroup[i]) then             timer.cancel(timerGroup[i])             timerGroup[i] = nil         end     end     -- remove display objects     for i = 1, #displayGroup do         displayGroup[i]:removeSelf()         displayGroup[i] = nil     end     -- call destructors of required modules     required1.onDestroy() package.loaded["required1"] = nil end

1.Is this destructor defined properly?

2.And what if there are a lot of transition and timer objects?

For example, I need to perform with delay quite often, will this occupy a lot of memory till I remove them?

3.Can I use the same timer object to do this repetitive delay?

I wonder will this cause conflict.

Thanks for reading. :slight_smile:

I want to ask if timer and transition objects will keep the memory once created?

Do I have to remove them manually?

Hi @hydralisk_mk2,

Unless you have explicitly set/associated a transition or timer object with a Lua variable that can’t be cleared (garbage-collected by Lua’s internal cleanup mechanism), these objects should clear from memory when they’re done.

Brent

So you mean if I use :

timerGroup[#timerGroup+1] = timer.performWithDealy()

It will not be collected.

But just

timer.performWithDealy()

Will be gc’ed.

I’m almost certain that if you simply add it as an element to “timerGroup”, it will nil itself out when complete… but of course, don’t forget to nil out “timerGroup” when you’re done with it.

Second case definitely, it will be garbage collected because it’s not associated with any variable.

Brent

I want to ask if timer and transition objects will keep the memory once created?

Do I have to remove them manually?

Hi @hydralisk_mk2,

Unless you have explicitly set/associated a transition or timer object with a Lua variable that can’t be cleared (garbage-collected by Lua’s internal cleanup mechanism), these objects should clear from memory when they’re done.

Brent

So you mean if I use :

timerGroup[#timerGroup+1] = timer.performWithDealy()

It will not be collected.

But just

timer.performWithDealy()

Will be gc’ed.

I’m almost certain that if you simply add it as an element to “timerGroup”, it will nil itself out when complete… but of course, don’t forget to nil out “timerGroup” when you’re done with it.

Second case definitely, it will be garbage collected because it’s not associated with any variable.

Brent