I’ve been working with Corona a few months now and I’ve realized maybe it’s time to start optimizing my code to run within the RAM constraints of some lower performing devices. (Up until now I’ve just been testing on my phone which has a fast CPU and plenty of RAM). My app runs great on the phone – smooth, high frame rate, no crashes.
Anyway, I decided to check out how much RAM the app is using on my phone. Upon startup, it’s around 30MB. That’s just the main menu with a background image and a couple of buttons.
Seems kind of high but no biggie. I noticed that if I don’t touch anything and switch back and forth between the app and Android settings (to see the ram usage) the RAM actually starts to go up – 32MB, 34 MB, 37MB…and it just keeps going up as I switch back and forth without actually touching anything in the app.
Once I get to the meat of the game the usage goes up even more 6 to 8MB at a time, without even interacting with the objects in the level (everything is static, no animations or anything). The RAM usage went past 100MB until I decided to stop checking.
Eventually I think the garbage collector kicks in and the usage goes down, but slowly starts to increase again.
So I looked at the storyboard.printMemUsage function in the simulator to see what’s going on. This is the printout that I got (during the main portion of the game where you actually play):
---------MEMORY USAGE INFORMATION--------- 2014-07-14 14:23:51.727 Corona Simulator[2840:507] System Memory Used: 0.833 Mb 2014-07-14 14:23:51.727 Corona Simulator[2840:507] Texture Memory Used: 2.940 Mb 2014-07-14 14:23:51.728 Corona Simulator[2840:507] ------------------------------------------
The numbers fluctuate as expected when I interact with the game and new objects get spawned, but the System Memory stays below 1Mb and Texture Memory stays less than 3Mb (I am taking care to remove display objects and nil out their references).
Enough of the boring stuff, here are my questions:
-
Why does the device show that the RAM usage is going up so much even though I’m not interacting with anything?
-
Why is the info from the storyboard.printMemUsage function nowhere near the amount of RAM being shown on the phone?
I can post the code from one of my scenes if anyone is interested.