Storyboard scenes and memory use?

I’m working on a top down 2D game that will have multiple interconnected adjacent screens that the player can transition too and from. I’m currently using a system where each screen is a Storyboard scene and when you move off the edge of one screen, that triggers the transition to the appropriate adjacent scene.

I had had some significant memory leaks initially which meant that every time I transitioned scenes my memory increased by about 30kb. This caused my game to bog within minutes to the point of being unplayable.

I’ve followed the advice from this blog tutorial and seem to have managed the five areas of consideration (display objects, global variables, runtime listeners, timers and transitions):
http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/
My memory no longer increases every time I switch scenes.

The one challenge I still face is that anytime I enter a new scene (ones I’ve never visited before), memory increases over all by about 8kb (memory remains stable if I’ve already been to the scene at some point, even though I purge scenes on loading a new scene). This memory growth is not an issue if my game “world” remains relatively small. I was planning on having 100 - 200 screens for the player to explore so in this case I’m anticipating a problem (have only built out about 6 screens at this point).

Is making each scene a screen of my “world” an unreasonable use of the Storyboard API (should I build a system for loading and removing my levels and only use scenes for menu, options, etc.)? If I’m purging scenes, I’m not clear on why new scenes would grow the over all memory usage. Is this 8kb increase per new scene expected? Does this indicate that I am still failing to manage my memory in some way? I have created some modules for common aspects of my levels. I believe I’m handling these correctly but could continue to investigate if the 8kb per new scene is unexpected.

Thanks in advance for any insight anyone has :slight_smile:
[import]uid: 105707 topic_id: 32150 reply_id: 332150[/import]

Is that nuts to use a storyboard scene for each of 100+ screens of a game or is that a reasonable application of the system?

As I mentioned my memory increases by about ~8kb per new scene and I can’t figure out why that is. I think I’ve solved all my memory leaks and the fact that it only happens the first time around on a scene I think supports that belief?

Is there anything in the storyboard API that would bump up memory usage the first time a scene is called?

I’d like to make a choice to either move on with storyboard for each screen or else build my own screen changing solution and just use storyboard for menu/options/leaderboards etc.

Thanks :slight_smile: [import]uid: 105707 topic_id: 32150 reply_id: 128568[/import]

Have you tried Director as an alternative for loading new modules as screens? That could help determine if it’s a core Lua memory issue or a Storyboard issue of something not being cleaned up properly…

Brent [import]uid: 9747 topic_id: 32150 reply_id: 128570[/import]

Is that nuts to use a storyboard scene for each of 100+ screens of a game or is that a reasonable application of the system?

As I mentioned my memory increases by about ~8kb per new scene and I can’t figure out why that is. I think I’ve solved all my memory leaks and the fact that it only happens the first time around on a scene I think supports that belief?

Is there anything in the storyboard API that would bump up memory usage the first time a scene is called?

I’d like to make a choice to either move on with storyboard for each screen or else build my own screen changing solution and just use storyboard for menu/options/leaderboards etc.

Thanks :slight_smile: [import]uid: 105707 topic_id: 32150 reply_id: 128568[/import]

Have you tried Director as an alternative for loading new modules as screens? That could help determine if it’s a core Lua memory issue or a Storyboard issue of something not being cleaned up properly…

Brent [import]uid: 9747 topic_id: 32150 reply_id: 128570[/import]

Hi Brent,

That’s a good idea regarding director. I had chosen not to use it in the first place though because of this mention that it apparently has memory issues over time?:
http://www.coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/

One thing I did just try was watching memory usage with the Storyboard sample that ships with the SDK. I even updated the example with the storyboard.purgeOnSceneChange = true flag so that each scene would purge it’s self after the goToScene was complete.

Remarkably, I was also experiencing the ~8kb mem usage increase per new screen (so only on the first display of a scene). So that would make me think this is just how storyboard works adding a small increase to total memory usage with each scene that you load the first time? Can anyone from Corona Labs confirm this? This is a significant decision point issue.

I’m thinking I may tackle my own solution for changing “rooms” in my game and just use storyboard to manage my menu/options/purchases screens… (so a much smaller number of total screens).

[import]uid: 105707 topic_id: 32150 reply_id: 128789[/import]

Hi Brent,

That’s a good idea regarding director. I had chosen not to use it in the first place though because of this mention that it apparently has memory issues over time?:
http://www.coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/

One thing I did just try was watching memory usage with the Storyboard sample that ships with the SDK. I even updated the example with the storyboard.purgeOnSceneChange = true flag so that each scene would purge it’s self after the goToScene was complete.

Remarkably, I was also experiencing the ~8kb mem usage increase per new screen (so only on the first display of a scene). So that would make me think this is just how storyboard works adding a small increase to total memory usage with each scene that you load the first time? Can anyone from Corona Labs confirm this? This is a significant decision point issue.

I’m thinking I may tackle my own solution for changing “rooms” in my game and just use storyboard to manage my menu/options/purchases screens… (so a much smaller number of total screens).

[import]uid: 105707 topic_id: 32150 reply_id: 128789[/import]

For as much as I’ve looked into Storyboard, I somehow had missed the distinction between purgeScene() and removeScene() (purgeScene() leaving some information in memory whereas removeScene() completely removes the scene).

I’ve now set my Storyboard based app to use removeAllScenes() at the start of each new scene (probably overkill, removeScene() in the didExit event of each screen might be better).

As long as I call removeAllScenes() at the start of each new scene I have removed that small per scene memory increase that is at the heart of my question with this thread (so I now have an app that seems to have stable memory usage regardless of how many scenes I go to). The stop that this put to the ~8kb memory increase per “unvisited” scene would be expected based on how purgeScene() leaves some info from the scene in memory.

What’s unexpected is that if I only call removeAllScenes() periodically (once every fifth scene for instance), memory does not go down to where it is if I’m removing each scene as I transition away from it. This is surprising to me. Whether I remove the excess memory with each scene or as a batch periodically, I would expect memory usage to be roughly the same once it’s removed.

Any insights on that?

Also, as I had heard mentioned elsewhere, could we get a storyboard.removeOnSceneChange = true flag? That would be very helpful if any Ansca/Corona staff read this :slight_smile:

[import]uid: 105707 topic_id: 32150 reply_id: 128948[/import]

For as much as I’ve looked into Storyboard, I somehow had missed the distinction between purgeScene() and removeScene() (purgeScene() leaving some information in memory whereas removeScene() completely removes the scene).

I’ve now set my Storyboard based app to use removeAllScenes() at the start of each new scene (probably overkill, removeScene() in the didExit event of each screen might be better).

As long as I call removeAllScenes() at the start of each new scene I have removed that small per scene memory increase that is at the heart of my question with this thread (so I now have an app that seems to have stable memory usage regardless of how many scenes I go to). The stop that this put to the ~8kb memory increase per “unvisited” scene would be expected based on how purgeScene() leaves some info from the scene in memory.

What’s unexpected is that if I only call removeAllScenes() periodically (once every fifth scene for instance), memory does not go down to where it is if I’m removing each scene as I transition away from it. This is surprising to me. Whether I remove the excess memory with each scene or as a batch periodically, I would expect memory usage to be roughly the same once it’s removed.

Any insights on that?

Also, as I had heard mentioned elsewhere, could we get a storyboard.removeOnSceneChange = true flag? That would be very helpful if any Ansca/Corona staff read this :slight_smile:

[import]uid: 105707 topic_id: 32150 reply_id: 128948[/import]

I assume you’re still using “purgeScene()” as you leave each scene, and then calling “removeAllScenes()” every 4-5 scene changes? I’m actually not familiar with Storyboard (I’m a loyal Director user myself) but I imagine you must still purge each scene when you leave it, to clear out some aspects of it, even if you don’t want to call “removeScene()” every time.

Brent
[import]uid: 9747 topic_id: 32150 reply_id: 129097[/import]

Hi Brent,

What I’m saying is that I actually get lower memory usage if I removeScene() each scene change rather than removeAllScenes() every fifth one! I was expecting that whether I remove each of five scenes one at a time or do all five at once, that I would end up with the same memory usage at that point. That seems not to be the case…

The good news is that by removing each scene as I leave it, I do seem to have a game that doesn’t slowly creep up in memory use. I have yet to try more than five scenes but it now seems possible to do a game that allows the player to go to 100 or more scenes in the course of a game session. [import]uid: 105707 topic_id: 32150 reply_id: 129102[/import]

I assume you’re still using “purgeScene()” as you leave each scene, and then calling “removeAllScenes()” every 4-5 scene changes? I’m actually not familiar with Storyboard (I’m a loyal Director user myself) but I imagine you must still purge each scene when you leave it, to clear out some aspects of it, even if you don’t want to call “removeScene()” every time.

Brent
[import]uid: 9747 topic_id: 32150 reply_id: 129097[/import]

Hi Brent,

What I’m saying is that I actually get lower memory usage if I removeScene() each scene change rather than removeAllScenes() every fifth one! I was expecting that whether I remove each of five scenes one at a time or do all five at once, that I would end up with the same memory usage at that point. That seems not to be the case…

The good news is that by removing each scene as I leave it, I do seem to have a game that doesn’t slowly creep up in memory use. I have yet to try more than five scenes but it now seems possible to do a game that allows the player to go to 100 or more scenes in the course of a game session. [import]uid: 105707 topic_id: 32150 reply_id: 129102[/import]