ios - 保留发送到释放的 UIViewController

标签 ios objective-c cocoa-touch uinavigationcontroller uikit

当我从导航 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/

相关文章:

iphone - UIImage 不是编译时常量,Xcode 4

ios - 使用自动布局向 UIButton 添加 subview

iOS:自定义 UITableViewCell 中的项目显示不一致。 Storyboard错误?

objective-c - 无法发送草稿中的附件 (Mail.app)

iphone - iOS异常处理问题

ios - 在代码中使用 Regular 以外的 iOS 系统字体样式

ios - MPNowPlayingInfoCenter 始终处于播放状态

iphone - 有没有办法将 iOS 应用程序转换为 Mac OS X 应用程序?

ios - 如何在我的文本字段中添加顶部填充(Objective-c)

ios - 如何正确推送 JSQMessagesViewController