Dear developers, I am running into a garbage collection issue only in testing on IPAD 4 retina display (IPAD mini, along with Samsung Tab 10.1......no issues at all). The issue is that when garbage collection triggers, it is causing a lag in gameplay for sometimes up to 4 to 5 seconds. I am trying to avoid GC collection during game play altogether.
I know I can fix this but do not know where to begin. Fundamentally, I believe the way I start a level is incorrect. I have gone through all the adobe material and other websites too, but am not sure what I can do to decrease the lag. This is the typical strategy I use when starting a level:
1. Declare all arrays using "new" (they typically hold a lot of numbers).....I have a lot of arrays as I have a lot of moving elements that rotate.
2. Load up all my bitmaps and mcs, again using the term "new".
3. During the level, I do not remove any child.
4. My game involves asteroids, but even though I may have as many as 48 entering the gameplay, I reuse them and only have 12 that are recycled. I do this with my missiles as well, and any other object that makes multiple appearances.
5. Once the level is completed, during the statistics portion where I tell the user some info about their performance, I call the pauseforGCIcollection set at 0.25
6. When either restarting the level or going to another level....I remove all the children, listeners (etc), null the variables ONLY for the mcs and bitmaps (not the arrays). If I am returning to the menu page, I again call the pauseforGCIcollection.......if I am retrying the same level or going to another level, I do not call the pauseforgcicollection and go back to step 1.
About 40% of the times, I get this lag on IPAD 4 retina during game action. On the mini, very rare.....on the Samsung....have never noticed it.
I do not mind putting in whatever effort I need to make this right for the IPAD 4, but have run out of tricks....if it is a fundamental change I need to make to steps 1 through 6, any suggestions you have would be much appreciated.
I think the issue I am having is that it is not clear to me how memory is managed. For example, with the arrays....do I need to null those too even if I am using the same arrays again when restarting the level and placing new elements into them?
Thank you,
Justin