我有以下问题。当我弹出视图控制器按下后面按钮时,dealLoc方法未被调用。

这是我正在使用的代码:

NSLog(@"coleccionVista retain count0: %i",[coleccionVista retainCount]);

coleccionVista = [[coleccionViewController alloc] init];
NSString *nombreColeccion = [colecciones objectAtIndex:i];
coleccionVista.nombreColeccion = nombreColeccion;
coleccionVista.title = [NSString stringWithFormat:coleccionVista.nombreColeccion];
NSLog(@"coleccionVista retain count1: %i",[coleccionVista retainCount]);

[self.navigationController pushViewController:coleccionVista animated:NO];
NSLog(@"coleccionVista retain count2: %i",[coleccionVista retainCount]);

[coleccionVista release];
//[coleccionVista release];
NSLog(@"coleccionVista retain count3: %i",[coleccionVista retainCount]);

我在控制台上收到这些消息:

我第一次推动视图:

2010-08-17 10:30:36.019 TAU 4[50133:207] coleccionVista retain count0: 0
2010-08-17 10:30:36.021 TAU 4[50133:207] coleccionVista retain count1: 1
2010-08-17 10:30:36.022 TAU 4[50133:207] coleccionVista retain count2: 3
2010-08-17 10:30:36.022 TAU 4[50133:207] coleccionVista retain count3: 2
2010-08-17 10:30:36.088 TAU 4[50133:207] coleccionViewController->viewWillAppear
2010-08-17 10:30:38.515 TAU 4[50133:207] coleccionViewController->viewWillDisappear

第二次:

2010-08-17 10:30:44.171 TAU 4[50133:207] coleccionVista retain count0: 1
2010-08-17 10:30:44.173 TAU 4[50133:207] coleccionVista retain count1: 1
2010-08-17 10:30:44.174 TAU 4[50133:207] coleccionVista retain count2: 3
2010-08-17 10:30:44.176 TAU 4[50133:207] coleccionVista retain count3: 2
2010-08-17 10:30:44.241 TAU 4[50133:207] coleccionViewController->viewWillAppear
2010-08-17 10:30:52.332 TAU 4[50133:207] coleccionViewController->viewWillDisappear

我在不显示的DealLoc方法上也有一个NSLOG消息。但是我注意到,如果我强迫另一个[coleccionvista释放]在另一个后,dealloc消息显示出来,但在尝试[Super DealLoc]时崩溃了。我没有持有ColeccionViewController的任何其他引用(我一直在代码中搜索,并且该方法的所有用途都在我向您显示的代码中)。

任何的想法?提前致谢!

有帮助吗?

解决方案

在五个方面,我想我弄清楚了发生了什么。我更改了很多代码,所以我不确定这一点,但是看来它是使用Coleccionvista类方法的NSTIMER,因此它正在维持类的参考,因此不可能是不可能的对它进行处理。

其他提示

两个大问题:

NSLog(@"coleccionVista retain count0: %i",[coleccionVista retainCount]);
coleccionVista = [[coleccionViewController alloc] init];

想必 coleccionVista 可能是非nil的,但是您没有在提出新的之前发布它。这要么是泄漏或崩溃。另请注意,retainCount返回nsuinteger,而不是int;用%i调用不确定的行为(通常这只是在Big-Endian 64位系统上打印错误的数字)。

[coleccionVista release];
NSLog(@"coleccionVista retain count3: %i",[coleccionVista retainCount]);

您正在释放一些东西。您不再拥有它。除非您 知道 还有其他东西拥有它。你可能想要 [coleccionVista release]; coleccionVista = nil; 要不就 self.coleccionVista = nil 如果您将其设置为属性。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top