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 关闭它),一切都会被释放,当您再次打开您的应用程序时,您将一无所有。

此外,单例的要点是您调用 getter 并检查其是否存在,如果不存在则创建它,因此如果您在某些时候没有它不应该有问题。

如果您在重新启动应用程序时需要持久数据,我建议您研究序列化和/或某种持久性

于 2013-01-29T13:35:58.240 回答