当我从导航 Controller 中弹出一个 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 帖子,但似乎没有什么相似之处,因为这是在没有悬空指针的 vanilla vc 上发生的。
编辑:
想补充一点,我正在使用 ARC,而 self.testVc 是一个弱引用。使用强引用是不可能的,因为那个内存会一直存在。
最佳答案
例如,如果您从 viewController B 弹出到 A.,那么请确保在 dealloc 方法之前没有释放 B View Controller 的任何 IBOutlet。
关于ios - 保留发送到释放的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27631589/