Skip to main content
October 9, 2013
Question

Garbage collection & memory management causing app to run poorly on iOS 7

  • October 9, 2013
  • 7 replies
  • 4891 views

Hi, I am currently working on a game built using Air SDK v. 3.8 that is running fine on iOS 6. However, since the release of iOS, sometime it becomes unresponsive. When profiling with Adobe Scout, the problem seems to have something to do with the garbage collection. In Scout, some GC pass could take up to few seconds on iOS 7, while it would never take more than 700 ms on iOS 6.

I've tried to compile the project using the new 3.9 beta, and the result is somewhere in between what we've got on iOS 6 and iOS 7 (1-2 seconds).

I'm wondering if this is something that you are aware of, and if there's a fix (or optimisation) around the corner. Thanks a lot.

This topic has been closed for replies.

7 replies

Known Participant
December 2, 2013

Are there any news about this??

I can't solve this problem and for us is critical as we can't launch an app like this

Participant
December 2, 2013

Last week at: https://bugbase.adobe.com/index.cfm?event=bug&id=3649713

Adobe has asked for a test project that demonstrates the problem.  If you can put one together for them, it will help them to analyze and fix the problem.  I don't have the bandwidth to do that right now, myself, unfortunately, and my existing project is too big and has server dependencies such that I cannot deliver it to them for use as a test case.

Participating Frequently
December 2, 2013

I'm working on a test application that will exhibit the issue, however I no longer have access to an ipad mini with ios6 to verify that the issue is not present using the test app.

Does anyone have an ipad mini with ios6 and would like to collaborate with me before we send something to adobe?

Known Participant
November 19, 2013

Maybe the problem has been solved here:

https://bugbase.adobe.com/index.cfm?event=bug&id=3649713

I'll give it a try

Participating Frequently
November 19, 2013

It seems a lot of the same things I reported in my bug are also listed here!

This is definitely a problem with ios7 and these devices. Rebooting the entire device seemed to fix the problem, albeit temporarily. When ios6 is installed on these devices, the GC works as expected and there is no performance problem.

The workaround was for Starling only and does not take into account any game code that might also be doing per-frame allocations.

I suggest loading up Scout and finding all the memory allocations happening each frame (generally function scoped variable declarations) and replacing them with instance variables or static variables (careful with static vars!)

I got our allocations down to 10-20 per frame and our performance is back to normal. Your mileage may vary. Good luck.

Participant
November 14, 2013

I am also seeing this.

Here are screenshots of Scout profiling the same sequence in my game on iPad 2 iOS 7 vs iPad 2 iOS 6.   The initial burst of activity is a loading sequence, followed by automated gameplay.

iOS 7: Please note the position of the red line on the graph, and the time associated with garbage collection.

iOS 6:

Ignoring the "loading sequence" section, the "vertical line" garbage collection spikes on the iOS 7 screen shot are on the order of 2-5 seconds (garbage collection time) each.  The biggest spikes in the iOS 6 screen shot are all < 50 ms in comparison (again, note the position of the red line on the graph). 

Earlier in the day I captured a few garbage collection spikes on iOS 7 that were > 10 seconds each, with the largest being a whopping 24 seconds.

Any insights, supporting evidence, or alternative theories are appreciated.

UPDATE: I tested an iPad3 iOS7 today and did not experience this behavior.

UPDATE: I tested with another iPad2 iOS7 and did see the behavior on that device as well.

Known Participant
November 18, 2013

I tested my game in an iPad 3 with ios 5 and it runs perfect.

If I run the same buil in an iPad Mini with ios 7 it starts doing all the garbage colleciton like crazy...

Jeff__Ward
Inspiring
November 18, 2013

The iPad2 (and mini, non-retina) has half the RAM of the iPad3 - it would potentially have a different gc tuning / behavior.  I suppose I need to upgrade one of our test devices and give this some testing.  =/

On the other (more paranoid) hand...

Apple is already actively degrading UX in their browser:  http://www.mobilexweb.com/blog/safari-ios7-html5-problems-apis-review.  Is it a stretch to imagine that they'd intentionally break cross-platform garbage-collection-based runtimes (AIR, phonegap?) on the app side as well?  I absolutely wouldn't put it past them.

Known Participant
November 11, 2013

It happens exactly the same to me with ios 7. Here is an image of what is going on:

Jeff__Ward
Inspiring
November 11, 2013

Like zeh_ said, while an OS or AIR bug isn't impossible, it's most likely that your app is calling some function that's wasteful of object allocation.  Here are a few ideas for investigation:

Take another couple screenshots and show us what happens under the 'Memory Allocations' tab under both 'allocations' and 'deallocations' (instead of 'Activity Sequence').  This will tell what objects your app is creating and destroying (i.e. Array, BitmapData, String).

Switching between "bottom-up" and "top-down" functions and objects will show you where in your code the de/allocations are coming from.  When searching for allocations, also select a few frames preceding the garbage collection event (as the allocations are potentially building up over time.)

For example, if you run JSON.parse(), you'll find a significant number of String's allocated and destroyed as this function is apparently quite wasteful, presumably during token parsing.

Known Participant
November 11, 2013

Well the thing is that I just restarted my computer and my Ipad Mini, and everything works perfect now

60 fps without any visible call to GC. Here is how it looks after restarting my computer and my Ipad:

Is not the first time that happens this to me. At least a couple times this strange GC behaviour has been solved by restarting my pc and making new builds...without changing any code in the app...

zeh
Inspiring
November 10, 2013

Regardless of the differences between versions, I'd say a garbage collection of 700ms is massive and something that should be avoided at all costs. This might be exacerbated by a bug in AIR or whatever, but the fact is, your code has a problem. Even if a specific device is being faster or delaying the GC call, the fact is, you need to avoid the need for GC calls as much as you possibly can.

In games, a good rule of thumb is to try and never re-allocate anything during the main game loop. Create whatever instances you need before the game start, and then manage them using object polls and re-using objects as much as possible. You should also dispatch gc (with System.gc or System.pauseForGCIfCollectionImminent()) strategically to prevent those long pauses.

jeromiec83223024
Inspiring
November 9, 2013

Moved to the AIR beta forum.

Participant
October 31, 2013

I also need any advice for this problem...

I have a same problem on iOS7.

My test device is iphone4s , iPad mini and iPhone5. The iOS version of thease devices are iOS7

In conclusion, iPhone5 do not have this problem. but iPhone4s and iPad mini have problem.

On the iPhone4 running on the iOS6 do not have this problem... (I didn't test iPhone4 on the iOS7)

I have heard the system memory of iPhone4s and iPad mini are 512Mb but iPhone5 is 1Gb...

No matter how the iOS7 is slower and need much more memory, it seems to have another reason of this problem.

I really hope so give me any mention of this problem.

Thank you.