开发者

UINavigationController releasing bonanza

At the end o开发者_高级运维f this code:

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];

The navigation controller appear modally, as usual, but when I click a button on the viewController, it crashes. In fact, the viewController has a retain count of 0. If I comment one of the two releases everything went better than expected. I have been seeing this code pretty much everywhere, what could be wrong?


The code you've posted is correct, but somewhere else you're over releasing something.

A few things to note:

First, never trust retainCount.

Second, make sure you're properly managing the memory of your nib objects as outlined here.

Finally, you'll need to use the NSZombie detection in Instruments to find out where your real problem lies. This video provides a nice how to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜