0

I have a setup where all of my singletons' live in an extern NSDictionary (I need it globally visible, since I make many subclasses from a base singleton object with some common features).

Everything is fine, but on an iPad 1 running iOS 5.0, when user puts the application to background (not terminates, just press the home button), this dictionary gets released (so all of my singleton services, subclasses, etc.). The more interesting, they get recreated when I switch back to the application, but "sometimes" they're not, and my application behaviour gets unpredictable.

I've put __strong before the declaration, but it results in the same. It is quiet harmful when my singletons are destroyed/created all over the time, since they are storing runtime user/application states.

It is important that I'm debuggin with Fastest, Smallest Optimization Level to simulate production environment.

Is there any way to prevent this behaviour? To make/mark it "really retained" somehow?

4

1 に答える 1

0

アプリケーションが「生きている」限り、リリースされるべきではありません。

アプリケーションが完全に終了した場合 (シミュレーターの再起動/iPad からの終了)、すべてが解放され、アプリを再度開いたときに何も表示されません。

また、シングルトンのポイントは、ゲッターを呼び出してその存在を確認し、存在しない場合は作成することです。そのため、ある時点でそれがなくても問題はないはずです。

アプリケーションを再起動したときに永続的なデータが必要な場合は、シリアライゼーションや何らかの永続化を検討することをお勧めします

于 2013-01-29T13:35:58.240 に答える