我有一个包含generic functions
的简单数组。如果在listeners
中存储了一些array
,我对leaks
有一个奇怪的问题。除了generic types
之外,Optional Numeric types
可以使用Double?
而不会有任何问题。如果我使用memory leak
,例如我有一个unowned/weak self
。此问题仅在我捕获@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var observations = [(Double?) -> Void]()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
observations.append { [unowned self] (new) in
print(self)
}
return true
}
}
时出现。有人可以解释为什么会出现这种泄漏以及如何解决这个问题吗?
observations
如果我将[(String?) -> Void]()
更改为05-25 14:36:02.745 I/TestRunner(15055): with id: uk.co.foobar.tm.free.debug:id/reset_timer'.
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
etc etc
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:472)
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:419)
05-25 14:36:02.745 I/TestRunner(15055): at android.support.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:240)
05-25 14:36:02.745 I/TestRunner(15055): at android
05-25 14:36:02.745 I/TestRunner(15055): ----- end exception -----
,那么就没有问题。