Why isn’t collectgarbage in the API? If collectgarbage ( “count” ) keeps going up, is this a problem? Should I be calling collectgarbage ( “collect” ) regularly?
[import]uid: 3018 topic_id: 5047 reply_id: 305047[/import]
Why isn’t collectgarbage in the API?
Technically it is, although I would agree that it’s not documented very well, especially considering how useful that command is. For example, it’s mentioned at the top of this page:
http://developer.anscamobile.com/content/memory-management-changes-corona-sdk-beta-8
If collectgarbage ( “count” ) keeps going up, is this a problem?
Probably. That situation is called a memory leak, since it’s like memory is gradually leaking out of your computer.
I say “probably” however because it’s possible and perfectly normal for the memory usage to steadily increase for a little while before garbage collection cycles catch up and stabilize the memory usage. If it keeps going up for just half a minute after you running, that may not mean anything. If it doesn’t stabilize after a while however then you have a problem.
Should I be calling collectgarbage ( “collect” ) regularly?
Possibly, but there are too many variables to make any sort of blanket statements. The garbage collector works automatically without you having to tell it to, but how often it works (ie. how quickly it clears memory) may need to be tweaked for your specific situation. [import]uid: 12108 topic_id: 5047 reply_id: 16610[/import]
If you’re going to extensively use graphic animations do not call collectgarbage() at each frame. It’s bad.
Rather, write a little code to control garbage collection as you wish and need.
If your app needs to free resources “on the need”, then you should be controlling the GC.
If your app is not going to do anything like that, then follow jhocking’s advice… don’t worry about calling collectgarbage() at all… it’s “automagic”. 
I’d suggest you have a look at the Lua manual and reference for more:
http://www.lua.org/manual/5.1/manual.html
http://www.lua.org/pil/
[import]uid: 5750 topic_id: 5047 reply_id: 16741[/import]
Is there a memory usage level that an app should not go above? [import]uid: 10903 topic_id: 5047 reply_id: 16760[/import]
For GC ? Unless you’re re-writing Windows in Lua, you don’t really need to worry. 
Memory allocated for graphics and sound is a different matter. Take good care of that instead. You have a fair amount of ram on i-devices but you better take a look at the specs of the system you want to develop for.
[import]uid: 5750 topic_id: 5047 reply_id: 16763[/import]
So for iphone 4 what might be a good graphics/sound usage level for a simple game? [import]uid: 10903 topic_id: 5047 reply_id: 16825[/import]
iPhone 4 got 512 Mb of shared RAM. That means you need to create a hell of a mobile game in order to run out of RAM.
[import]uid: 5750 topic_id: 5047 reply_id: 16835[/import]
@erpy, do you have an example how to take good care of memory allocated to sound? [import]uid: 8353 topic_id: 5047 reply_id: 19780[/import]
Here is the section on collectgarbage from the Lua 5.1 manual:
collectgarbage ([opt [, arg]])
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
“collect”: performs a full garbage-collection cycle. This is the default option.
“stop”: stops the garbage collector.
“restart”: restarts the garbage collector.
“count”: returns the total memory in use by Lua (in Kbytes).
“step”: performs a garbage-collection step. The step “size” is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle.
“setpause”: sets arg as the new value for the pause of the collector (see §2.10). Returns the previous value for pause.
“setstepmul”: sets arg as the new value for the step multiplier of the collector (see §2.10). Returns the previous value for step.
[import]uid: 104085 topic_id: 5047 reply_id: 105625[/import]
I would say you should shoot to not exceed 33-50% of the available RAM on your minimum supported device. In the iOS case, that’s a iPhone 3Gs and an iPad (first edition). Both only have 256M of memory, so in the 80-125mb range. Though that may be too generous.
[import]uid: 19626 topic_id: 5047 reply_id: 105647[/import]