Storyboard killed the director-class?

Hi!

Is Director Class dead?

I am struggling with Memory managing my app which uses the director class.
I have found plenty of comments and posts about director but the most recent one was from April 2012,
and the one before that December 2011.

Im leaking a small amount every time I use my restart button and I need to fix that because it is a one level game, so restarting will occur lotsa lotsa times.

Has anyone figured out a good memory leak clean up for director since April?
All director clean up discussions seem to end up with people recommending storyboard… And I dont have time to switch.

Thanks.
[import]uid: 199163 topic_id: 33674 reply_id: 333674[/import]

Hello,
Have you determined that the memory leak is related to Director (director.lua, actually), or your own code? Unless you changed or edited the Director module itself, it shouldn’t be leaking memory.

Ultimately, it’s probably a matter of checking your code down to the last detail to ensure that you’re cleaning up everything on scene change that Director doesn’t/can’t clean up, like listeners, stray timers, unfinished transitions, tables containing references to other objects, streaming audio or audio channels not disposed, etc. etc.

I don’t know the future of Director, but if the developer isn’t releasing updates or responding to issues, he might have decided to give it up, especially since Storyboard is the “official” scene management solution now.

Brent [import]uid: 200026 topic_id: 33674 reply_id: 133987[/import]

Hey Brent!

I am a bad cleaner so I will delve down in to the text based abyss that is my code and find the loose ends.

The reason I blamed director class (Which I really like btw) is because I read manier posts and threads about leakage and fixing of leakage. Modules being faulty and storyboard being complicated but leak free.

Do you know of any other tutorial than http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/ ? [import]uid: 199163 topic_id: 33674 reply_id: 133998[/import]

Hi DPN Sweden,
I am also facing the same issue from last 10 months that after some screen transition (using director class), my game becomes slow and continue slowing as more screen transitions takes place.

i’ve debugged the code a number of time to manage my memory, but now i am thinking that the only remaining code in director.lua which may cause any issue to make my game slow.
For corona staff, you guys can check my launched application on the link given below and play it for some time. You can guess it better.

https://play.google.com/store/apps/details?id=ikonamitech.com&feature=search_result#?t=W251bGwsMSwxLDEsImlrb25hbWl0ZWNoLmNvbSJd

Regards,
Haroon Yaseen [import]uid: 108129 topic_id: 33674 reply_id: 134002[/import]

Hello @DPN Sweden and @Haroon,

Unfortunately, I don’t have a better “guide” than the one you linked to read about proper cleanup. It’s just a matter of checking everything on the “most common list” and ensuring that you cleared and nil’led it out of Lua’s memory. This list is what I posted above (and there might be even more to add), but I always check for these:

  1. object listeners (tap, touch, etc.) / Runtime listeners – basically, anywhere you type :addEventListener(), you need to ensure that you :removeEventListener() on the same object and listening function when you exit the scene.

  2. incomplete timers – if you have a timer running for more than a few milliseconds, I suggest you attach it to a local reference, then when you exit the scene, you cancel that timer explicitly.

  3. unfinished transitions – same approach as timers

  4. tables containing references to other objects – sometimes, you might add a reference to an object (like a button) to another Lua table, so you have those buttons as a known collection. When you exit the scene, ensure that you FIRST empty out the containing table", THEN you remove the items themselves.

  5. backwards-iterate through tables to clear items – if you are looping through a table of objects to clear them, never loop from 1 to the # of table items. Instead, loop from the # of items backwards to 1. Why? Because if you start at #1, and clear that object, the #2 entry then becomes entry #1, but Lua has skipped to #2, which was previously #3. In other words, you will only clear every other item in the table. Working from the total number backward to 1, you clear out all of them.

--example table  
local myButtons = { button1, button2, button3, button4 }  
  
--BAD!  
for i=1,#myButtons do  
 myButtons[i]:removeEventListener( "tap", onButtonTap )  
 display.remove( myButtons[i] ) ; myButtons[i] = nil  
end  
--GOOD!  
for i=#myButtons,1,-1 do --loop backwards from end to start! (-1 specifies reverse iteration)  
 myButtons[i]:removeEventListener( "tap", onButtonTap )  
 display.remove( myButtons[i] ) ; myButtons[i] = nil  
end  
  1. streaming audio or audio channels not disposed – you MUST dispose audio when you’re done with it. On scene exit, you should STOP all audio channels, then dispose of all channels too.
--load the sound  
local mySound = audio.loadSound( "audio/harp.mp3" )  
--on scene exit, stop all audio and dispose the sound  
audio.stop()  
audio.dispose( mySound ) ; mySound = nil  

Hope this helps! Memory leaks are the bane of all programmers, and proper cleanup is the only way to prevent those leaks. Storyboard certainly isn’t “leak-proof” either; I see plenty of forum posts about Storyboard modules leaking memory because the proper cleanup steps weren’t followed. :slight_smile:

Brent [import]uid: 200026 topic_id: 33674 reply_id: 134046[/import]

Hi brent.

Thank you for the help, the reverse loop looks very nice. [import]uid: 199163 topic_id: 33674 reply_id: 134133[/import]

Hi Brent,
Thanks for such a great and informative reply. I’ve already worked on many of your given points. I’ve not used story board because that was not introduced at that time. I’ve used modules and screen transitions are managed by using director.lua class.
Now, i find an article on memory leaks while using modules and packages (used a number of modules), so working on it.

Kind Regards,
Haroon Yaseen [import]uid: 108129 topic_id: 33674 reply_id: 134146[/import]

Hello,
Have you determined that the memory leak is related to Director (director.lua, actually), or your own code? Unless you changed or edited the Director module itself, it shouldn’t be leaking memory.

Ultimately, it’s probably a matter of checking your code down to the last detail to ensure that you’re cleaning up everything on scene change that Director doesn’t/can’t clean up, like listeners, stray timers, unfinished transitions, tables containing references to other objects, streaming audio or audio channels not disposed, etc. etc.

I don’t know the future of Director, but if the developer isn’t releasing updates or responding to issues, he might have decided to give it up, especially since Storyboard is the “official” scene management solution now.

Brent [import]uid: 200026 topic_id: 33674 reply_id: 133987[/import]

Hey Brent!

I am a bad cleaner so I will delve down in to the text based abyss that is my code and find the loose ends.

The reason I blamed director class (Which I really like btw) is because I read manier posts and threads about leakage and fixing of leakage. Modules being faulty and storyboard being complicated but leak free.

Do you know of any other tutorial than http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/ ? [import]uid: 199163 topic_id: 33674 reply_id: 133998[/import]

Hi DPN Sweden,
I am also facing the same issue from last 10 months that after some screen transition (using director class), my game becomes slow and continue slowing as more screen transitions takes place.

i’ve debugged the code a number of time to manage my memory, but now i am thinking that the only remaining code in director.lua which may cause any issue to make my game slow.
For corona staff, you guys can check my launched application on the link given below and play it for some time. You can guess it better.

https://play.google.com/store/apps/details?id=ikonamitech.com&feature=search_result#?t=W251bGwsMSwxLDEsImlrb25hbWl0ZWNoLmNvbSJd

Regards,
Haroon Yaseen [import]uid: 108129 topic_id: 33674 reply_id: 134002[/import]

Hello @DPN Sweden and @Haroon,

Unfortunately, I don’t have a better “guide” than the one you linked to read about proper cleanup. It’s just a matter of checking everything on the “most common list” and ensuring that you cleared and nil’led it out of Lua’s memory. This list is what I posted above (and there might be even more to add), but I always check for these:

  1. object listeners (tap, touch, etc.) / Runtime listeners – basically, anywhere you type :addEventListener(), you need to ensure that you :removeEventListener() on the same object and listening function when you exit the scene.

  2. incomplete timers – if you have a timer running for more than a few milliseconds, I suggest you attach it to a local reference, then when you exit the scene, you cancel that timer explicitly.

  3. unfinished transitions – same approach as timers

  4. tables containing references to other objects – sometimes, you might add a reference to an object (like a button) to another Lua table, so you have those buttons as a known collection. When you exit the scene, ensure that you FIRST empty out the containing table", THEN you remove the items themselves.

  5. backwards-iterate through tables to clear items – if you are looping through a table of objects to clear them, never loop from 1 to the # of table items. Instead, loop from the # of items backwards to 1. Why? Because if you start at #1, and clear that object, the #2 entry then becomes entry #1, but Lua has skipped to #2, which was previously #3. In other words, you will only clear every other item in the table. Working from the total number backward to 1, you clear out all of them.

--example table  
local myButtons = { button1, button2, button3, button4 }  
  
--BAD!  
for i=1,#myButtons do  
 myButtons[i]:removeEventListener( "tap", onButtonTap )  
 display.remove( myButtons[i] ) ; myButtons[i] = nil  
end  
--GOOD!  
for i=#myButtons,1,-1 do --loop backwards from end to start! (-1 specifies reverse iteration)  
 myButtons[i]:removeEventListener( "tap", onButtonTap )  
 display.remove( myButtons[i] ) ; myButtons[i] = nil  
end  
  1. streaming audio or audio channels not disposed – you MUST dispose audio when you’re done with it. On scene exit, you should STOP all audio channels, then dispose of all channels too.
--load the sound  
local mySound = audio.loadSound( "audio/harp.mp3" )  
--on scene exit, stop all audio and dispose the sound  
audio.stop()  
audio.dispose( mySound ) ; mySound = nil  

Hope this helps! Memory leaks are the bane of all programmers, and proper cleanup is the only way to prevent those leaks. Storyboard certainly isn’t “leak-proof” either; I see plenty of forum posts about Storyboard modules leaking memory because the proper cleanup steps weren’t followed. :slight_smile:

Brent [import]uid: 200026 topic_id: 33674 reply_id: 134046[/import]

Hi brent.

Thank you for the help, the reverse loop looks very nice. [import]uid: 199163 topic_id: 33674 reply_id: 134133[/import]

Hi Brent,
Thanks for such a great and informative reply. I’ve already worked on many of your given points. I’ve not used story board because that was not introduced at that time. I’ve used modules and screen transitions are managed by using director.lua class.
Now, i find an article on memory leaks while using modules and packages (used a number of modules), so working on it.

Kind Regards,
Haroon Yaseen [import]uid: 108129 topic_id: 33674 reply_id: 134146[/import]