为什么这段代码会调用自动释放池?
我看到以下日志...
“__NSAutoreleaseNoPool(): UITableViewCellContentView 类的对象 0x58264b0 自动释放,没有池 - 只是泄漏”
这是一个巨大的发布池日志,上面只是我复制的发布日志之一。我
有一个 CustomCell,它根据业务逻辑向自身添加图块。但问题是当我调用单元格的创建时,我看到了上面的日志消息。我没有发现我的代码有任何问题。有人对此有任何线索吗?
- (UITableViewCell *) tableView:(UITableView *)inTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UnSavedNoteListCell *cell;
NSString *CellIdentifier = [@"Cell_" stringByAppendingString:[NSString stringWithFormat:@"%d", indexPath.row]];
cell = (UnSavedNoteListCell *)[inTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSMutableArray *cellProgressNoteCollection = [self getcellProgressNoteCollectionForLandScape:indexPath];
cell = [[[UnSavedNoteListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier cellTiles:cellProgressNoteCollection] autorelease];
cell.backgroundColor = [UIColor clearColor];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
// cell.textLabel.text = [NSString stringWithFormat:@"%d", rand()];
// cell.textLabel.textColor = [UIColor redColor];
// Configure the cell...
return cell;
}
I am seeing the following log...
"__NSAutoreleaseNoPool(): Object 0x58264b0 of class UITableViewCellContentView autoreleased with no pool in place - just leaking "
It is a huge release pool log, above is just one of the release log that i copied...
I have a CustomCell that adds tiles into itself depending on the business Logic. But the problem is when I call the creation of the cell, i see the above log messages. I don't see anything wrong with my code.. Does any one has any clue about it?
- (UITableViewCell *) tableView:(UITableView *)inTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UnSavedNoteListCell *cell;
NSString *CellIdentifier = [@"Cell_" stringByAppendingString:[NSString stringWithFormat:@"%d", indexPath.row]];
cell = (UnSavedNoteListCell *)[inTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSMutableArray *cellProgressNoteCollection = [self getcellProgressNoteCollectionForLandScape:indexPath];
cell = [[[UnSavedNoteListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier cellTiles:cellProgressNoteCollection] autorelease];
cell.backgroundColor = [UIColor clearColor];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
// cell.textLabel.text = [NSString stringWithFormat:@"%d", rand()];
// cell.textLabel.textColor = [UIColor redColor];
// Configure the cell...
return cell;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到的一件事是,您没有重用任何 uitableviewcell,因此您的性能可能会受到很大影响。在上面的代码中,您为每一行创建一个新的单元格标识符。尝试这样做:
这样,您的表视图可以维护标记为重用的表单元格列表。
One thing I do notice is that you're not reusing any of your uitableviewcells, so you're probably taking on a big performance hit. In your code above, you're creating a new cell identifier for every row. Try this instead:
This way, your tableview can maintain a list of tablecells that are marked for reuse.
更好的问题是为什么你没有自动释放池。
以下是您在该代码中进行的一些可能需要自动释放池的调用。 (实际上,其中一些可能没有。):
stringByAppendingString
stringWithFormat
dequeueReusableCellWithIdentifier
autorelease
getcellProgressNoteCollectionForLandScape< /code> (如果按照约定编写)
clearColor
(理论上,但可能不是)UIKit 需要一个自动释放池。
我发现您有两个潜在原因:
A better question is why you don't have an autorelease pool.
Here's some of the calls you make in that code that might require an autorelease pool. (Some of them probably don't, actually.):
stringByAppendingString
stringWithFormat
dequeueReusableCellWithIdentifier
autorelease
getcellProgressNoteCollectionForLandScape
(if it's written per conventions)clearColor
(theoretically, but probably not)UIKit requires an autorelease pool.
You have two potential causes that I see: