Reputation: 886
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
Edit: 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. –
Edit: 5/16
Getting this error message in the log
* -[CustomTVC controllerWillChangeContent:]: message sent to deallocated instance 0x187270
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.
Upvotes: 4
Views: 1145
Reputation: 886
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:]
Edit(s): Finally took the time to figure out how to put code in here correctly (I'm lazy)
Upvotes: 2
Reputation: 7
you are assigning controller to tableViewControllerIvar
self.tableViewControllerIvar = controller;
and you are releasing controller, so you need to retain it in the above line
self.tableViewControllerIvar = [controller retain];
and when you are done with your "tableViewControllerIvar" then just release it, you shall not get any leaks after that
Upvotes: -1
Reputation: 3228
autorelease
should get the job done. When you assign tableViewControllerIvar
, you can just call [controller autorelease]
. This should take care of that.
CustomTVC* controller = [[CustomTVC alloc]initWithStyle:UITableViewStyleGrouped];
controller.managedObjectContext = self.managedObjectContext;
self.tableViewControllerIvar = [controller autorelease];
[self.navigationController pushViewController:self.VCTVC animated:YES];
If you are still getting EXE_BAD_ACCESS, then something else must be going on. Have you absolutely confirmed that this code, when run more than once, is causing the bad access?
Upvotes: 0