I am very confused at the following code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RPSAdvisorViewController *pushThis = [[RPSAdvisorViewController alloc]init];
pushThis.opponentName = [opponentArray objectAtIndex:indexPa开发者_如何学Cth.row];
[self.navigationController pushViewController:pushThis animated:YES];
//[pushThis release];
}
The if the line [pushThis release] does not get commented out, the app would crash when I pop back out of that view. I thought I always need to released the viewControllers that I allocated, but this time the app won't let me.
I even tried testing for leaks in instruments like this without releasing pushThis, there are no leaks.
I am really confused, can some one tell me why I'm not suppose to release pushThis?
Edit1: The crash will produce this error message:
-[CALayer release]: message sent to deallocated instance 0x4e66b20
It appears that when the navigationController pops the view controller, it trys to send release to pushThis again, which was already released. If I don't release everything works perfectly, instruments does not show any leaks even if i repeatedly push and pop the view controller.
You have to release it because when you push view controller, navigation controller take ownership of that controller.
I think there might be some views hierarchy issue with your app.Can you please check that?
I can only guess that there is some problem with RPSAdvisorViewController
. Can you try replacing it with a place-holder UIViewController and see what happens?
精彩评论