UITableViewCell AutoRelease导致崩溃...?

问题描述:

不知道是否有人知道是否存在实际限制的UITableViewCells数量不断被重新利用......?首先,我很清楚所有的Obj-C/Apple内存管理规则(我会首先说明,所以我不会浪费任何人的时间,也不会浪费我的)UITableViewCell AutoRelease导致崩溃...?

所以我会问这个问题out ...是否存在一些关于重用UITableViewCell的“Autorelease”机制的实际限制..?因为我似乎只是经历了一定数量的崩溃,所以通常超过50页的单元格(大约50页+ 50单元格)被翻上......然后出于否定 - 我会在这里崩溃..有时从不发生在所有的,有时会发生相当频繁,这取决于内容密度...

它会更好手动启动保持和释放我自己..? 如果是这样,有人会有经验推荐一个好地方释放他们..?

[tableview tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x14e0a920 

好吧....我没能找到任何与实际的UITableViewCell(单元格内容或细胞本身),但增加后的数保留到控制器(其实例化的UITableView对象)的“撞车”神秘就不来了......

这里是我的改变。基本上,我添加了三个Retain语句,顺便说一下,我使用了自定义的“Iphone专家”中的“How To” - “UITabBarController”的原始示例教程,但是“专家”否定了保留.... (这只是规则的适用部分...)

//initialize the UITabBarController 
tabBarController = [[UITabBarController alloc] init]; 
TabBarControllerSet = TRUE; 

//Create the first UITabBarItem 
MainMessageBoard *mainMessageBoard = [[MainMessageBoard alloc] initWithController: self]; 
[mainMessageBoard setTitle:@"?????"]; 
[mainMessageBoard retain]; ////******** ADDED This RETAIN *********** 

//Create the second UITabBarItem 
PostNewComment *postNewComment = [[PostNewComment alloc] initWithController: self]; 
[postNewComment setTitle:@"????"]; 
[postNewComment retain]; ////******** ADDED This RETAIN *********** 

//Create the third UITabBarItem 
logout *Logout = [[logout alloc] initWithController: self]; 
[Logout setTitle:@"?????"]; 
[Logout retain]; ////******** ADDED This RETAIN *********** 


//add the UIViewControllers to the UITabController 
tabBarController.viewControllers = [NSArray arrayWithObjects:mainMessageBoard, postNewComment, Logout, nil]; 
[tabBarController setDelegate:self]; 

//release 
[mainMessageBoard release]; 
[postNewComment release]; 
[Logout release]; 

[self.view addSubview:tabBarController.view]; 
+2

你能解释一下多一点 - 为什么正是你得到一个崩溃?你有什么样的视图结构(50个页面各有50个单元 - 你有50个不同的表格视图?)。也许发表您的cellForRowAtIndexPath方法... – Vladimir 2011-05-06 08:25:52

+1

为什么你认为你的代码是完美的,它是一个苹果的限制 - 发布一些代码:) – deanWombourne 2011-05-06 09:10:17

据我所知它是由在设备上释放内存只有有限的 - 我假设它使用的自动释放池某种动态组和在表格视图的可重复使用的单元格中(即NSSet或更低级别的等效单元格)。

我用用行数万表视图没有任何问题。

+0

谢谢...那么它一定是在我结束的东西.... – NpC0mpl3t3 2011-05-09 23:17:10

+0

会缺乏TabBarController上的“retain”导致TableViewController将转储作为:tableview tableView:cellForRowAtIndexPath:]:发送到释放实例0x14e0a920的消息...?我添加了一个保留,现在我处理/重用了超过4500个单元格,但没有发生任何事件(截至目前为止......)...尽管类似这样的崩溃必须由更加恶毒的事情引起,比如明确地释放在使用或类似的...? – NpC0mpl3t3 2011-05-10 07:08:37

+0

好吧,如果你的tabBarController被autoreleased,那么它会被释放,而不是你;)听起来像是这个问题,很好的工作! – deanWombourne 2011-05-10 08:54:09