简体   繁体   English

模拟器上的Singleton与真实设备上的Singleton?

[英]Singleton on the Simulator vs singleton on a real device?

I am using a singleton for some shared stuff. 我正在使用单例做一些共享的东西。 In the simulator, the app crashes ocasionally. 在模拟器中,该应用偶尔崩溃。 Tracking the crash down shows that the the properties of my singleton became dealocated. 跟踪崩溃表明,我的单例属性已取消分配。 Those crashes never happend on a real device. 这些崩溃从未在真实设备上发生过。 Does the simulator handle memory managemend different? 模拟器处理内存管理是否不同? GC maybe? GC也许?

Changed the singleton to match this pattern . 更改了单例以匹配此模式 The Simulator dont crash now, but I am not sure about the memory handling on the real device. Simulator现在不会崩溃,但是我不确定真实设备上的内存处理。 I assume that this solution will cause problems. 我认为这种解决方案会引起问题。

What do you think? 你怎么看?

You probably had the singleton wrong in the first attempt. 您可能在第一次尝试中遇到了单例错误。 Memory management on the Simulator works the same way as on the device, at least in principle. 至少在原理上,模拟器上的内存管理与设备上的内存管理相同。 In practice there are some differences because of timing issues or because the Simulator has plenty memory and will not send you the memory warnings. 实际上,由于时序问题或模拟器具有足够的内存并且不会向您发送内存警告,因此存在一些差异。 But these differences will not affect a correctly written singleton. 但是这些差异不会影响正确编写的单例。

The linked singleton code looks good on a skim. 链接的单例代码看起来很不错。 In my opinion you would do best to get rid of the singletons completely and wire your application using Interface Builder or dependency injection. 我认为您最好是完全摆脱单例,并使用Interface Builder或依赖项注入来连接您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM