如果我释放,我得到不好的访问,如果我保留,我泄漏 [英] If I release, I get bad access, if I retain, I leak

查看:99
本文介绍了如果我释放,我得到不好的访问,如果我保留,我泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器,我试图推到导航堆栈。我创建一个局部变量的控制器,设置它,然后将其分配给一个属性。然后如果我释放变量,我得到EXE_BAD_ACCESS。如果我保留(或自动释放)它泄漏。

I have a view controller that i'm trying to push onto the navigation stack. I create the controller with a local variable, set it up, then assign it to a property. Then if I release the variable, I get EXE_BAD_ACCESS. if I retain (or auto release) it leaks.

CustomTVC* controller = [[CustomTVC alloc]initWithStyle:UITableViewStyleGrouped];
controller.managedObjectContext = self.managedObjectContext;

self.tableViewControllerIvar = controller;

[self.navigationController pushViewController:self.tableViewControllerIvar animated:YES];
 //[controller autorelease]; or [controller release]; or nothing

这是发布的时候发生的事情

Here is exactly what happens if I release


  1. 上面的代码是通过在导航栏中按下添加按钮引发的。

  2. 视图被推送,一切正常。在新视图中,我可以反复推送更多视图,没有问题...除非

  3. 我回到导航堆栈的根视图。

  4. 现在,如果我再次向下钻取第二个视图,那么尝试推其它视图崩溃。

  1. The above code is fired from pushing an add button in the nav bar.
  2. the view is pushed and everything is fine. In the new view I can push more views in over and over with no problem...unless
  3. I go back to the root view of the navigation stack. (Which is where the above code is from).
  4. Now if I drill down again to the second view, then try to push another it crashes.

编辑:我有一种感觉,当我把第三个控制器推到堆栈上时,出现了问题。使用push,它将一个新的对象插入托管对象上下文,这导致fetchedresultscontroller更新tableview。在某处可能有一个破碎的指针。我会玩它,并发布的结果。 -

I have a feeling that something is going wrong when I push the third controller onto the stack. With the push, it's inserting a new object into the managed object context which is causing the fetchedresultscontroller to update the tableview. There may be a broken pointer in there somewhere. I'll play with it and post the results. –

编辑:5/16

在日志中取得此错误讯息

Getting this error message in the log


* - [CustomTVC controllerWillChangeContent:]:传送至解除分配执行个体的讯息0x187270

* -[CustomTVC controllerWillChangeContent:]: message sent to deallocated instance 0x187270

这只发生在我离开堆栈的CustomTVC(回到导航根视图控制器),我可以推并保存我想要的,只要我不会弹出CustomTVC。

This only happens after I pop the CustomTVC off the stack (go back to the navigation root view controller) I can push and save all I want as long as I don't pop the CustomTVC.

推荐答案

修复了它。不得不在viewDidLoad中将获取的结果控制器委托为nil。

Fixed it. Had to set the fetched results controllers delegate to nil in viewDidLoad.

- (void)dealloc
{
    self.fetchedResultsController.delegate = nil;
    [_fetchedResultsController release];
    [_managedObjectContext release];
    [super dealloc];
}

似乎是罪魁祸首(根据僵尸仪器):

seems the culprit was(according to the zombie instruments):

[NSFetchedResultsController(private methods)_managedObjectContextDidChange:]

[NSFetchedResultsController(private methods) _managedObjectContextDidChange:]

编辑:最后花时间了解如何代码在这里正确(我懒惰)

Edit(s): Finally took the time to figure out how to put code in here correctly (I'm lazy)

这篇关于如果我释放,我得到不好的访问,如果我保留,我泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆