Memory Management Problems

Hi all,

I’ve been using Corona since January or so to develop my thesis project and I’ve hit a problem that I’ve been unable to figure out. My project is the development of a game for use in a psychological study with kids and I’ve been using the Storyboard API to move between menu screens and into the actual game. Everything works just fine on the simulator (XCode & Corona) but when I build for my iPad, the game crashes with low memory errors.

www.protobear.com//assets/srice/projects/Pig%20Pandemonium.zip

The project can be found at that link though I won’t ask anyone to look at it (unless you’re feeling particularly helpful) as its not streamlined by any means. I’ll post relevant code snippets and my questions below.

I’ve been using the following lines of code in order to watch memory usage:

local memUsage\_str = string.format( "memUsage = %.3f KB. texture = %.3f", collectgarbage( "count" ), (system.getInfo( "textureMemoryUsed")/1000000) ) print(memUsage\_str);

I print this in enterScene so I can watch what my memory looks like as I move through the program. What I notice is this:

  1. Memory Usage (the first value printed out) is based on each individual scene alone. I.E. The title screen always takes ~162 KB of memory, the name input screen takes ~127, etc.

  2. The texture memory in use is additive. It seems as if my texture memory is never being released with each scene taking up additional memory until the app crashes on the device (where memory is limited).

This second issue seems to be where my app is having problems (obviously) but I’ve been unable to reduce my texture memory use. Upon entering each new scene, I purge the previous scene (which unloads the previous scene and frees its memory, at least as I understand it).

In each scene’s exitScene, I’ve also tried to unload my images and sprite sheets. I’ve attempted to do this in multiple ways:

randomObject:removeSelf(); randomObject = nil;

display.remove(randomObject); randomObject = nil;

In the case of spriteSheets:

display.remove(randomSpriteSheet); randomSpriteSheet = nil;

randomSpriteSheet:dispose(); randomSpriteSheet = nil;
I’ve scoured this site and any posts I could find on how to properly free memory but nothing I’ve tried seems to actually work. Am I missing some fundamental feature of unloading memory or is it possible that I’m on the wrong track altogether?

Any help you can give would be greatly appreciated!

Stephen

Note: For those interested in actually downloading and looking over my actual project, the file/scene order is: Main --> Title --> Name Input --> Character Select --> Waiting --> Versus --> Game. You may notice that I’m faking the connection to a second “player.” This is a feature of the actual psych study to make kids think they are playing against other kids instead of the computer.

Note2: I also am aware that some of my code is inefficient or not in best practices (I just noticed the stickied optimization post and plan to adapt much of my code to those standards). I apologize for any winces my code may have caused!

[import]uid: 97503 topic_id: 26473 reply_id: 326473[/import]

I am curious if you ever got this fixed or what the solution was? I kind of have the same problem. And I am doing pretty much the same as you when releasing Spritesheets etc. [import]uid: 152474 topic_id: 26473 reply_id: 124045[/import]

The answer is a definitive maybe. I was contacted by another user who had encountered similar problems and found a solution (which was then forwarded to me). I’ve got it implemented in my code but I’m waiting for my project lead to renew the apple developer’s license so I can test it on device. If you’re not opposed, I can forward those e-mails to you so you can take a look. [import]uid: 97503 topic_id: 26473 reply_id: 124062[/import]

That’s ok. I think spending about 4 hours, today of tinkering and troubleshooting I got mine figured out. Basically I changed the sample story board by purging the current scene on exit. That was not working, so then I added a purgeall () in the enterscene function, and that cleaned up everything for me. My app is a book app, so I don’t need to retain anything from page to page. I would assume just dump everything and start over with page2, page3, etc…that’s what I figured out this morning. [import]uid: 152474 topic_id: 26473 reply_id: 124063[/import]

I am curious if you ever got this fixed or what the solution was? I kind of have the same problem. And I am doing pretty much the same as you when releasing Spritesheets etc. [import]uid: 152474 topic_id: 26473 reply_id: 124045[/import]

The answer is a definitive maybe. I was contacted by another user who had encountered similar problems and found a solution (which was then forwarded to me). I’ve got it implemented in my code but I’m waiting for my project lead to renew the apple developer’s license so I can test it on device. If you’re not opposed, I can forward those e-mails to you so you can take a look. [import]uid: 97503 topic_id: 26473 reply_id: 124062[/import]

That’s ok. I think spending about 4 hours, today of tinkering and troubleshooting I got mine figured out. Basically I changed the sample story board by purging the current scene on exit. That was not working, so then I added a purgeall () in the enterscene function, and that cleaned up everything for me. My app is a book app, so I don’t need to retain anything from page to page. I would assume just dump everything and start over with page2, page3, etc…that’s what I figured out this morning. [import]uid: 152474 topic_id: 26473 reply_id: 124063[/import]