How to clean up a module with Director 1.4?

Hi

How do I clean up a module with Director 1.4? … Do I need to remove everything in my localgroup manually? And how do I remove eventlisteners and transitions in Director 1.4? What function do I need to call in the end of the module to succesfully clean the module -> localGroup.clean = function () … end or clean = function ()? I think there is lack of documentation to Director.

Thank you for the answers :slight_smile: [import]uid: 122802 topic_id: 27451 reply_id: 327451[/import]

I’ve also been looking for information about this. I’m particularly interested in clean-up at the end of scenes when using Director. Does anyone know of any good resources or tips in this matter?

Thanks,

-Brandon [import]uid: 136211 topic_id: 27451 reply_id: 125707[/import]

I’ve also been looking for information about this. I’m particularly interested in clean-up at the end of scenes when using Director. Does anyone know of any good resources or tips in this matter?

Thanks,

-Brandon [import]uid: 136211 topic_id: 27451 reply_id: 125707[/import]

I wanted to follow up and see if anyone else had any information on this… I’m using Director on a project and I notice a memory increase each time I go to a new scene. The scenario goes something like this:

Start scene1 --> memUsage = 450kb
Go to scene 2 --> memUsage = 520 kb
back to scene1 --> memUsage = 500 kb
back to scene2 --> memUsage = 520 kb
back to scene1 --> memUsage = 500 kb
etc…

So I’m not sure if this is a bonfide leak because it only happens this FIRST time you leave a scene. I’m concerned if the memUsage collects 50 more kb every scene that it’ll get pretty hairy if the user plays 30 in a row. Is this a Director issue or something else perhaps?

Anyone have any thoughts on this? Thanks,

Brandon [import]uid: 136211 topic_id: 27451 reply_id: 126179[/import]

I am not sure if this is what your looking for but, as i remember it… Its up to YOU to clean up any timers and transitions you start in a “scene”.

When you do a Director change scene event, Director launches the new scene, but as soon as it starts the new scene Director calls a CLEAN function from the LAST scene it just left, which can be used to clean up any timers / listeners you need to stop. The function must always be named “clean”

I put this function at the bottom of every one of my scenes with director. Also note, you dont have to do anything to CALL this function. Director automatically calls it for you. As long as your scene has one and its named exactly this.

[lua] --************************************************************************
–***** Change Scenes Clean Up
–************************************************************************
function clean (event)
–print (“Clean Play Game”)
–Particles.CleanUp() – This Cleans up ALL PARTICAL CANDY ITEMS
–Runtime:removeEventListener( “enterFrame”, heartBeat )
if timer1 then timer.cancel(timer1) end
if timer2 then timer.cancel(timer2) end
if timer3 then timer.cancel(timer3) end
if timer4 then timer.cancel(timer4) end
if gravityShift then timer.cancel(gravityShift) end
end
–********** END of non Direcotr CODE ***********************
return localGroup – Director - MUST return a display.newGroup()
end – Director Function end[/lua] [import]uid: 88147 topic_id: 27451 reply_id: 126187[/import]

Thanks for the response. I was aware that it was our responsibility to keep track of our transitions and timers but I’ve been using a 3rd party module called “tnt” for the ability to pause my transitions. I enjoy the module (and it does include a “cancelAllTimers()” function, etc) but I realized it was partially responsible for another leaky-type situation I had. I wonder if it is causing this one too. I may need to strip all my tnt related code out and see what happens…

And thanks for pointing out how the “clean()” function works. I had heard it referenced it other forum posts but was unable to find any solid documentation on it. Good to know.

Brandon [import]uid: 136211 topic_id: 27451 reply_id: 126189[/import]

I wanted to follow up and see if anyone else had any information on this… I’m using Director on a project and I notice a memory increase each time I go to a new scene. The scenario goes something like this:

Start scene1 --> memUsage = 450kb
Go to scene 2 --> memUsage = 520 kb
back to scene1 --> memUsage = 500 kb
back to scene2 --> memUsage = 520 kb
back to scene1 --> memUsage = 500 kb
etc…

So I’m not sure if this is a bonfide leak because it only happens this FIRST time you leave a scene. I’m concerned if the memUsage collects 50 more kb every scene that it’ll get pretty hairy if the user plays 30 in a row. Is this a Director issue or something else perhaps?

Anyone have any thoughts on this? Thanks,

Brandon [import]uid: 136211 topic_id: 27451 reply_id: 126179[/import]

I am not sure if this is what your looking for but, as i remember it… Its up to YOU to clean up any timers and transitions you start in a “scene”.

When you do a Director change scene event, Director launches the new scene, but as soon as it starts the new scene Director calls a CLEAN function from the LAST scene it just left, which can be used to clean up any timers / listeners you need to stop. The function must always be named “clean”

I put this function at the bottom of every one of my scenes with director. Also note, you dont have to do anything to CALL this function. Director automatically calls it for you. As long as your scene has one and its named exactly this.

[lua] --************************************************************************
–***** Change Scenes Clean Up
–************************************************************************
function clean (event)
–print (“Clean Play Game”)
–Particles.CleanUp() – This Cleans up ALL PARTICAL CANDY ITEMS
–Runtime:removeEventListener( “enterFrame”, heartBeat )
if timer1 then timer.cancel(timer1) end
if timer2 then timer.cancel(timer2) end
if timer3 then timer.cancel(timer3) end
if timer4 then timer.cancel(timer4) end
if gravityShift then timer.cancel(gravityShift) end
end
–********** END of non Direcotr CODE ***********************
return localGroup – Director - MUST return a display.newGroup()
end – Director Function end[/lua] [import]uid: 88147 topic_id: 27451 reply_id: 126187[/import]

Thanks for the response. I was aware that it was our responsibility to keep track of our transitions and timers but I’ve been using a 3rd party module called “tnt” for the ability to pause my transitions. I enjoy the module (and it does include a “cancelAllTimers()” function, etc) but I realized it was partially responsible for another leaky-type situation I had. I wonder if it is causing this one too. I may need to strip all my tnt related code out and see what happens…

And thanks for pointing out how the “clean()” function works. I had heard it referenced it other forum posts but was unable to find any solid documentation on it. Good to know.

Brandon [import]uid: 136211 topic_id: 27451 reply_id: 126189[/import]