【问题标题】:Retain sent to deallocated UIViewController保留发送到释放的 UIViewController
【发布时间】: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.testVcweak 引用而不是Strong
  • 是的,self.testVc 是一个弱引用。

标签: ios objective-c cocoa-touch uinavigationcontroller uikit


【解决方案1】:

例如,如果您从 viewController B 弹出到 A.,那么请确保您没有在 dealloc 方法之前释放 B 视图控制器的任何 IBOutlet。

【讨论】:

    猜你喜欢
    • 2015-05-23
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 2014-09-12
    • 1970-01-01
    相关资源
    最近更新 更多