【发布时间】:2015-02-22 06:11:52
【问题描述】:
当我从导航控制器弹出一个 VC 并模拟内存警告时,我遇到了一个问题,应用程序将崩溃。 NSZombies 向我展示了它是哪个 vc,但有趣的是,它发生在一个没有代码的普通 UIViewController 上。
这是我的推送代码:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:
(NSIndexPath *)indexPath {
self.testVc = [[ZTestVCViewController alloc] init];
[self.navigationController pushViewController:self.testVc animated:YES];
}
当我模拟内存警告时会发生以下情况:
2014-12-23 20:28:12.776 ----[3518:78070] Received memory warning.
2014-12-23 20:28:12.778 ----[3518:78070] *** -[ZTestVCViewController retain]: message sent to deallocated instance
我这辈子都想不通。
我浏览了其他 SO 帖子,但似乎没有什么相似之处,因为这是在没有悬空指针的香草 vc 上发生的。
编辑:
想补充一点,我正在使用 ARC,而 self.testVc 是一个弱引用。使用强引用是不可能的,因为这种记忆会一直存在。
【问题讨论】:
-
你实现
didReceiveMemoryWarning方法了吗? -
确认
self.testVc是weak引用而不是Strong -
是的,
self.testVc是一个弱引用。
标签: ios objective-c cocoa-touch uinavigationcontroller uikit