How often to manually do garbage collection?

Do you guys use this a lot?

collectgarbage("collect")

I'm finding that my app crashes a lot on the device when switching between screens. Even though I'm destroying things from the first screen, it seems like when the app loads the new screen, it loads all the new graphics before emptying the texture memory from the previous screen. Do I need to manually place the above code in my destroy() method of each screen module?

Personally I don't use collectgarbage at all. I'm sure there are legitimate uses for it, but I never understood that voodoo.

So far every device crash that I thought was caused by some kind of memory issue turned out to be due to something else (usually something dumb I was doing, occasionally a bug or limitation of Corona itself), and collectgarbage isn't a band-aid for that. Though it's easy enough to try it and see if it fixes your crash.

Check to make sure the two screens really add up to more than the total texture memory on the device. Try a test with the same transition code but with fewer graphics to see if it still crashes. If you really are bumping into the maximum texture memory of the device unfortunately you might have to rethink the graphics approach of your game.

As powerful as these devices are you still have to bow down to their physical limitations. For example, you can't hold 10 2048x2048 pixel images in texture memory at the same time the way you can on a mediocre desktop pc.

i don't see collectgarbage() in the api listing. i think that means it is not implemented.

collectgarbage() is part of the lua language, not an Ansca-made api.

I would be great if a lua guru or Ansca team member (Mr. Beebe?) could chime in with thoughts on garbage collection. It seems like some programmers sprinkle it their code for good measure, but I haven't found any clear cut guidelines for its correct use.

@jn19: did it fix your crash issues on devices?

views:1596 update:2011/9/28 8:56:32
corona forums © 2003-2011