【发布时间】:2018-01-30 16:30:23
【问题描述】:
我目前在我的 Objective-C 应用程序中使用这种方法:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEnteredForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
如果我不删除它
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
我是否有内存泄漏的风险?或者有没有一种很好的方法来利用这个通知而不会有内存泄漏的风险?
【问题讨论】:
-
NSNotificationCenter不保留其观察者,所以不,您没有内存泄漏的风险。 -
字!随意折腾一个答案,我会接受它!
-
@TomHammond 但不仅如此。存在悬空指针的危险(iOS 9 之前的版本)。
标签: ios objective-c memory-leaks