我使用单例作为整个应用程序中使用的本地化字符串,字典键和通知名称的容器。它初始化如下:
class ConstantsManager {
private init() {}
class var sharedInstance: ConstantsManager {
struct Static {
static let instance: ConstantsManager! = ConstantsManager()
}
return Static.instance
}
let localization = "NSLocalizedString(etc.)"
let dictKey = "aKey"
let notificationName = Notification.Name("name")
}
首次使用单例出现在AppDelegate的应用程序中(_ application:didFinishLaunchingWithOptions :)。当仪器/泄漏达到
时让manager = ConstantsManager.sharedInstance
指示泄漏。下面的调用树是否表明初始化发生了两次?我想知道与第二次初始化相关的属性是否代表泄漏。奇怪的是,模拟器上不会发生泄漏。 (我正在使用Xcode 8.2.1和OS X 10.12.3进行iOS 10.2部署。)
Bytes Used # Leaks Symbol Name
448 Bytes 100.0% 14 ConstantsManager.init() -> ConstantsManager
448 Bytes 100.0% 14 ConstantsManager.__allocating_init() -> ConstantsManager
448 Bytes 100.0% 14 globalinit_33_8D935C4E2193156DAA2AB3DF99F55E80_func0
448 Bytes 100.0% 14 static ConstantsManager.(sharedInstance.getter).(Static #1).instance.unsafeMutableAddressor
448 Bytes 100.0% 14 static ConstantsManager.sharedInstance.getter
448 Bytes 100.0% 14 AppDelegate.registerUserDefaults() -> ()
448 Bytes 100.0% 14 AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool
448 Bytes 100.0% 14 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool
448 Bytes 100.0% 14 main