导航,内存泄漏后,自定义UITableViewCell不会被释放或重用

时间:2016-10-31 19:02:00

标签: ios objective-c uitableview memory-leaks

我有一个类,它定义了一个名为ContactItemCell的自定义联系单元格和一个用于布置该单元格的xib文件。当我创建表视图时,它会打开,并创建其中六个ContactItemCell类。当我向后导航时,它们不会被释放,当我再次打开tableview时,会创建另外6个。这是tableview代码:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Contact* contact = [self contactAtIndexPath:indexPath];

    static NSString *cellID = @"ContactItemWithTagsForBothCell";
    ContactItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    if (cell == nil)
    {
        NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"ContactItemWithTagsForBothCell" owner:nil options:nil];

        if (arr.count <= 0)
        {
            NSLog(@"couldnt find cell with ID: %@", cellID);
            return nil;
        }

        cell = [arr firstObject];
    }

    [cell configureCellForContact:contact];

    return cell;
}

xib文件中的文件所有者只是设置为空白,我假设它意味着NSObject。我已经尝试寻找一个强大的参考周期,看看这个班级是否通过指针保持活着,但经过几天的调查我没有看到任何东西。我真的在我的极限,我不知道我还能做什么,我一直在使用乐器,这就是我怎么知道它们一次被创造6但我找不到是什么指向他们。为什么会这样?我在表格视图中做错了吗?如果我不是,并且您认为它是一个强大的参考周期,那么我如何才能找到指向此ContactItemCell的每个对象?提前谢谢!

1 个答案:

答案 0 :(得分:2)

如果有人好奇我使用了内存调试器,发现我使用的pod有一个强大的参考周期。