我写了以下一段代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
GameViewController *gameViewController = [[GameViewController alloc]initWithLevelNumber:([levelGroup intValue]*100+indexPath.row) Bonus:NO];
NSLog(@"Retain Counter =%d",gameViewController.retainCount);
[navController pushViewController:gameViewController animated:YES];
[gameViewController release];
NSLog(@"Retain Counter=%d",gameViewController.retainCount);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
两个日志的结果依次为1和6!这怎么可能?我只调用一次 alloc 方法并在将控制器压入堆栈后释放.. alloc-> +1, push-> +1, release-> -1 = 1 与否?
当我将视图控制器从堆栈中弹出时,我希望视图控制器被释放。