change view error
Hi when I switch from one view to another, I do:
-(void)goInGame {
InGameViewController = [[InGameView alloc] initWithNibName:@"InGameView" bundle:nil];
[self presentModalViewController:self.InGameViewController animated:NO];
[InGameViewController release];
}
However, in this way retain count of InGameViewController is "0", but the retain count of InGameView is "-1", and sometimes crashes
error: Terminating app to two Uncaught exception 'NSInternalInc开发者_Python百科onsistencyException', reason: 'Could not load bundle NIB:' NSBundle <.... app> (loaded) 'with name ' InGameView''
where am I wrong?
thanks!
I don't understand why you want to explicitly release your controller. Try removing the line [InGameViewController release];
and see if that fixes your problem.
For more information, check out Apple's Memory Management Rules as well as Behind the Scenes: Retain Counts in the Memory Management Programming Guide, which states that
If an object’s retain count is reduced to 0, it is deallocated (see “Deallocating an Object”).
Furthermore,
Important: Typically there should be no reason to explicitly ask an object what its retain count is (see retainCount). The result is often misleading, as you may be unaware of what framework objects have retained an object in which you are interested. In debugging memory management issues, you should be concerned only with ensuring that your code adheres to the ownership rules.
Your application crashes because it is trying to access your view controller, which has already been deallocated.
精彩评论