Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this over-releasing? UINavigationController / UITableview

I'm pushing a view controller onto my navigation controller's stack from within my TableViewController's didSelectRowAtIndexPath method as so:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
MyObject *myO = (MyObject *)[appDelegate.myOs objectAtIndex:indexPath.row];
myViewController.amount = myO.amount;
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];

If I uncomment that last line then the app crashes upon return with an error:

-[CALayer release]: message sent to deallocated instance 0xd4f860

Digging in a bit further I find the crash can further be narrowed down to the call to [super dealoc] within MyViewController's dealoc method. By uncommenting "[super dealoc]" we don't crash.

I'm having trouble narrowing this down further. "super" would be the UIViewController class and I can't further investigate that dealoc method...can I? Maybe there's a way to see what exactly 0xd4f860 was pointing to but I'm not aware how? Any ideas?

like image 772
Meltemi Avatar asked Jul 22 '09 18:07

Meltemi


1 Answers

You're looking in the wrong place -- the problem is that myViewController is getting released (or autoreleased) too many times.

The code you have posted looks correct, so I'd look at MyViewController's code to see if it ever releases itself, or somehow causes itself to be released by other means.

You could also override the release method, set a break point and see if you can narrow it down that way... e.g.

- (void)release {
    [super release]; //Set breakpoint here
}
like image 176
Daniel Dickison Avatar answered Nov 15 '22 01:11

Daniel Dickison