Ipad 使用navigationController弹出viewController时释放内存时出现问题

Ipad 使用navigationController弹出viewController时释放内存时出现问题,ipad,uinavigationcontroller,release,dealloc,pushviewcontroller,Ipad,Uinavigationcontroller,Release,Dealloc,Pushviewcontroller,我有以下问题。当我按下后退按钮弹出视图控制器时,没有调用dealloc方法 以下是我正在使用的代码: NSLog(@"coleccionVista retain count0: %i",[coleccionVista retainCount]); coleccionVista = [[coleccionViewController alloc] init]; NSString *nombreColeccion = [colecciones objectAtIndex:i]; coleccion

我有以下问题。当我按下后退按钮弹出视图控制器时,没有调用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消息没有显示。但我注意到,如果我在另一个版本之后强制发布另一个[ColeCionVista版本],则会显示dealloc消息,但在尝试[super dealloc]时会崩溃。我没有持有coleccionViewController的任何其他引用(我一直在代码中搜索,该方法的所有用法都在我向您展示的代码中)


有什么想法吗?提前谢谢

最后我想我知道发生了什么。我更改了很多代码,所以我不确定,但似乎是一个NSTimer使用了coleccionVista类的方法,因此它维护了该类的引用,因此无法取消分配它。

两个大问题:

NSLog(@"coleccionVista retain count0: %i",[coleccionVista retainCount]);
coleccionVista = [[coleccionViewController alloc] init];
据推测,
colecionvista
可能是非nil的,但在指定新版本之前,您不会发布它。这不是泄漏就是撞车。还要注意,-retainCount返回的是整数,而不是int;将其格式化为%i将调用未定义的行为(通常这只是在big-endian 64位系统上打印错误的数字)

你在释放一些东西。你不再拥有它了。除非你知道它是别人的,否则使用它是不安全的。您可能想要
[coleccionVista发行版];coleccionVista=nil
或者如果您已将其设置为属性,则只需
self.coleccionVista=nil

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