If I let go, I get poor access, if I keep, I will miss

I have a view controller that I am trying to push on the navigation stack. I create a controller with a local variable, configure it, and then assign a property to it. Then, if I free the variable, I get EXE_BAD_ACCESS. if I save (or auto-vacation), it flows.

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 

This is what happens if I release

  • The above code is triggered by clicking the add button in the navigation bar.
  • the view is clicked and everything is in order. In the new view, I can repeatedly increase the number of views without problems ... if
  • Back to the root view of the navigation stack. (This is the code from which the code is called).
  • Now, if I turn around again to the second view, try clicking another one that works.

Edit: I have a feeling that something is wrong when I push the third controller onto the stack. Using push, it inserts a new object into the context of the managed object, which causes the fetchedresultscontroller to update the table view. There may be a broken pointer. I will play with him and publish the results. -

Edit: 5/16

Getting this error message in the log

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

This only happens after I pulled CustomTVC from the stack (return to the root navigation view controller). I can click and save everything I want until I use CustomTVC.

+4
source share
3 answers

Fixed. If the intended recipients of the results have delegated nil to viewDidLoad.

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

It seems the culprit was (according to zombie tools):

[NSFetchedResultsController (private methods) _managedObjectContextDidChange:]

Edit (s): Finally, it's time to figure out how to paste the code correctly (I'm lazy)

+2
source

autorelease should do its job. When you assign tableViewControllerIvar , you can just call [controller autorelease] . That should take care of this.

 CustomTVC* controller = [[CustomTVC alloc]initWithStyle:UITableViewStyleGrouped]; controller.managedObjectContext = self.managedObjectContext; self.tableViewControllerIvar = [controller autorelease]; [self.navigationController pushViewController:self.VCTVC animated:YES]; 

If you still get EXE_BAD_ACCESS, then there must be something else. Have you absolutely confirmed that this code causes poor access when you run it more than once?

0
source

you assign tableViewControllerIvar to the controller

  self.tableViewControllerIvar = controller; 

and you free the controller, so you need to save it in the line above

  self.tableViewControllerIvar = [controller retain]; 

and when you finish your "tableViewControllerIvar" and then just let it go, after that you will not get any leaks

-1
source

All Articles