【问题标题】:UITableViewCell AutoRelease causing crash...?UITableViewCell AutoRelease 导致崩溃...?
【发布时间】:2011-05-06 08:20:50
【问题描述】:

不确定是否有人知道不断重复使用的 UITableViewCell 的数量是否存在实际限制......?首先我很清楚所有的 Obj-C / Apple 内存管理规则,(我会先说明这一点,所以我没有浪费任何人的时间,他们也没有浪费我的时间)

所以我会直接问这个......关于重用 UITableViewCell 附加的“自动释放”机制是否有一些实际限制......?因为我似乎只是在一定数量后才经历崩溃,通常超过 50 页的单元格(大约 50 页 + 50 个单元格)会被翻过来......然后不知从何而来我会遇到这个崩溃......有时永远不会完全发生,有时发生得相当频繁,具体取决于内容密度...

我自己开始手动保留和释放会更好吗? 如果是这样,是否有人有经验推荐一个释放它们的好地方..?

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

好的....我找不到与实际 UITableViewCell(单元格内容或单元格本身)有关的任何内容,但是在向控制器(实例化 UITableView 对象)添加了一些保留之后,“崩溃”神秘地停止了出现...

这就是我所做的更改。基本上我添加了三个 Retain 语句,顺便说一句,我使用了“如何”的原始示例教程 - 自称“Iphone 专家”的“​​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];

【问题讨论】:

  • 您能否再解释一下 - 为什么会发生崩溃?你有什么样的视图结构(哪里有 50 个页面,每个页面有 50 个单元格 - 你有 50 个不同的表格视图?)。可能发布您的 cellForRowAtIndexPath 方法...
  • 为什么你认为你的代码是完美的,这是苹果的限制——发布一些代码:)

标签: iphone cocoa-touch ios uitableview autorelease


【解决方案1】:

AFAIK 仅受设备上可用内存的限制 - 我假设它在自动释放池和表格视图的可重用单元格中使用某种动态集(即 NSSet 或更低级别的等效项)。

我已经使用了数万行的表视图,没有任何问题。

【讨论】:

  • tabBarController 上缺少“保留”是否会导致 TableViewController 将转储为:tableview tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x14e0a920...?我添加了一个保留,现在我处理/重用了超过 4500 个单元而没有发生任何事件(到目前为止......)......我虽然这样的崩溃必须是由一些更令人发指的事情引起的,比如明确释放的东西是在使用中或类似...?
  • 好吧,如果您的 tabBarController 被自动释放,那么它就会被释放,而不是由您释放;)听起来这就是问题所在,干得好!
猜你喜欢
  • 1970-01-01
  • 2013-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-23
  • 2020-12-02
  • 2013-11-11
相关资源
最近更新 更多