0

While doing some testing, I noticed that my Cocos2D app was struggling pretty badly. This was weird because the app itself is not doing intense calculations, doesn't have items scheduled every update, and is generally simple.

Aside from the fact that I have not optimized images using TexturePacker or the like, I could not think of any reason why this might be happening.

Upon further testing using the Memory profiler in Instruments, I discovered that regardless of what state the device was currently in (running an app, sitting at the home screen, etc.), Maps was using 20-30MB of device memory. The App Store and Springboard were likewise using the same amount. I understand why the Springboard needs to stay running in memory, but why on earth are Maps and the App Store running in my app's sandbox?

I thought that once an app was exited, it was no longer in main memory. It has been my belief this whole time that any app can run in its sandbox, and that's about it - and that you were not required to double-tap the home screen and 'force quit' the app from the quick menu. However, force quitting Maps and the App Store was the only way to free up the necessary memory. Have my assumptions been wrong all this time? Is this just an Apple thing that I am forced to work around for memory intense applications?

4

1 に答える 1

4

アプリは「サンドボックス内」で実行されていません。それらは独自のサンドボックスで実行されているか、サンドボックス化されていない幸運なAppleアプリです(組み込みのものはそうで、App Storeにインストールされたものはそうではないと思います)。

iOS の「サンドボックス化」の目的は、アプリが想定されていないデータにアクセス (読み取りと上書きの両方) するのを防ぐことであり、「終了した」アプリが RAM を使用するのを防ぐことではありません。iOS 4 (3GS+) 以降、「終了した」アプリはデフォルトでバックグラウンドでロードされたままになります。さらに、Apple は、少なくとも iOS 3 以降、Safari がバックグラウンドでロードされたままになることを許可しています (iOS 1 以降では、毎回ページをリロードすると思います)。ブラウザに切り替えたのはかなりひどいです)。

重要でないバックグラウンド アプリも、アプリが「必要なメモリ」を使用するのを防ぐことはできません。OS はバックグラウンド アプリを強制終了して、必要に応じてメモリを解放します。典型的なデスクトップとは異なり、iOS はスワップを使用しません — バックグラウンド アプリによって "使用中" のメモリは、本質的にアプリの速度を低下させるべきではありません。

私が考えることができることがいくつかあります:

  • バックグラウンド アプリは引き続き CPU を使用できます (そうであるかどうかは、Instruments によって通知されます)。これは実際には問題になりません。フォアグラウンド アプリよりも低い優先度で実行されると思います。
  • 新しいマップは OpenGL を使用します。iOS がバックグラウンド GL コンテキストを効率的に処理していない場合、問題が発生する可能性があります。これはかなり深刻なバグになります。
  • アプリは、メモリ警告をトリガーするのに十分な数のテクスチャをロードし、すべてのテクスチャを破棄してメモリ警告を処理します (調べるために を追加NSLog()-applicationDidReceiveMemoryWarning:ます)。アプリがフォアグラウンドにある場合は、次のフレームで必要になるテクスチャを破棄しないでください。これは Cocos2D のバグである可能性があります。

メモリの警告でない場合は、アプリをプロファイリングして、どのビットが遅いかを調べてみます。

psメモリ警告にはさまざまな「レベル」もありますが、これにアクセスできるかどうかはわかりません(おそらくのuserInfo辞書にありUIApplicationDidReceiveMemoryWarningNotificationます)。この場合、それは問題ではありません。次の秒で再びメモリを使用する場合、メモリを解放するのは単に非生産的です。

于 2013-03-07T02:03:49.443 に答える