开发者

iPhone Memory Usage Optimization / Performance Tuning

I am in the last phase of my iphone game development: optimization and performance tuning. My problem is, the game runs quite smooth on iphone 4 and iPad, but it often crashes on iPhone 2 with iOS 3.1.3 due to low memory.

I have gone through all the memory leak detection / clean up processes, and the Xcode instrument shows no leak except those from system library (see following screenshot). I also use "autorelease" rarely.

(bigger picture: click here)

iPhone Memory Usage Optimization / Performance Tuning

I also profiled my application using "CPU Sampler" and "Allocations", but is a little confused by the result. This is the result from开发者_如何学JAVA "Allocation" benchmark:

(bigger picture: click here)

iPhone Memory Usage Optimization / Performance Tuning

This is the result after one game. As you can see, the "Live Bytes" is only 3.93MB, which shouldn't be a big deal (according to my understanding) -- but the game often crashes at this time on iPhone 2, ios 3.1.3 .

I also did a "CPU sampler" benchmark, following is the result:

(bigger picture: click here)

iPhone Memory Usage Optimization / Performance Tuning

What confused me is, the real memory shows "22.32MB" and the virtual memory is more than 100MB, which is dramatically different from the result of "Allocation benchmark".

I am also confused by the fact that, my iPhone 3G, running iOS 4.1, even if it has almost exactly same hardware spec with iPhone 2, can run my game very well. It's slow and not as snappy, but it rarely crashs.

So my questions are:

  1. What else I can do to identify the low memory issue on iphone 2?
  2. Are the leaks from system libraries on the "Leaks" profiling result a problem?
  3. Why "CPU sampler" and "Allocation" shows different memory foot print? Did I read them correctly?
  4. Why iPhone 3G runs a lot more smoother than iPhone 2G? Is it because the newer iOS version (4.1 vs 3.1.3)?


1. What else I can do to identify the low memory issue on iphone 2?

Run your app in iOS simulator and use Hardware menu item "Simulate Memory Warning" item to trigger Out-Of-Memory events in places, which you suspect to crash.

Instrument your app in real device, but before launching it start as many other apps as possible to reduce amount of available memory. While running your app, switch every now and then back to app grid to (re)launch other apps. This way you will make system generate genuine Out-Of-Memory events, but you can't choose which app will receive them.

You could generate OOM events by yourself, but then you would be running a different application. Might be useful, while developing, but not recommended when close to release. Very annoying to debug bugs caused by debugging "helper" routines...

2. Are the leaks from system libraries on the "Leaks" profiling result a problem?

They could be side-effects of your code. Look around which part of your app might be starting that system service and whether you release / cancel / close everything.

3. Why "CPU sampler" and "Allocation" shows different memory foot print? Did I read them correctly?

No idea, but would like to know :)

4.Why iPhone 3G runs a lot more smoother than iPhone 2G? Is it because the newer iOS version (4.1 vs 3.1.3)?

iPhone 3G has better, faster and more hardware than iPhone2. As result, apps seem to run faster... which can be a problem, if your app runs too fast in faster hardware. Making sure your app runs "just right speed" regardless of hardware is a different question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜