为什么这个过度释放? UINavigationController / UITableview [英] Why is this over-releasing? UINavigationController / UITableview

查看:213
本文介绍了为什么这个过度释放? UINavigationController / UITableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的TableViewController的didSelectRowAtIndexPath方法中将视图控制器推送到我的导航控制器的堆栈中:

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

进一步挖掘我发现崩溃可以进一步缩小到在MyViewController的dealoc方法中调用[super dealoc]。通过取消注释[超级dealoc]我们不会崩溃。

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.

我无法进一步缩小范围。 super将是UIViewController类,我不能进一步调查dealoc方法...可以吗?也许有一种方法来看看什么0xd4f860指向,但我不知道如何?任何想法?

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?

推荐答案

你正在寻找错误的地方 - 问题是myViewController被释放(或自动释放)太多次了。

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

您发布的代码看起来是正确的,所以我将看看MyViewController的代码,看看它是否释放自己,或者以某种方式释放自己的代码通过其他方式。

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
}

这篇关于为什么这个过度释放? UINavigationController / UITableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆