Note that there are some explanatory texts on larger screens.

plurals
  1. POSubclassed UITableViewCell Creates Zombie Unless Retained
    primarykey
    data
    text
    <p>I've created a UITAbleViewCell subclass with a custom nib, and am using it in two different UITableViews in my app. It works perfectly in one of the tables, but the other table crashes when I scroll it vigorously. Instruments identifies a zombie in this code (in cellForRowAtIndexPath):</p> <pre><code>NSString *identifier = @"edit"; LogTableCell *cell = (LogTableCell*)[tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = (LogTableCell*) [[[NSBundle mainBundle] loadNibNamed:@"LogTableCell" owner:self options:nil] objectAtIndex:0]; [cell retain]; // prevents zombies! } NSLog(@"%@: retainCount: %d", identifier, [cell retainCount]); // some other cell init stuff return cell; </code></pre> <p>Notice the [cell retain]; line - when it's in there, the code works swimmingly. Take it out, and crash. NSLog always reports a retainCount of 2, so it shouldn't be necessary. But if I do something like this:</p> <pre><code> if ([cell retainCount] &lt; 1) { [cell retain]; } // does not prevent zombies! </code></pre> <p>it doesn't work. There's no alloc/init, so I shouldn't have to do an autorelease or worry about this at all, and I've always thought that cellForRowAtIndexPath releases the cell for me.</p> <p>When I'm not using Instruments, here's the error I get from xcode:</p> <pre><code>*** -[CALayer retain]: message sent to deallocated instance 0x4d8e930 </code></pre> <p>Even though it works with the [cell retain]; line, it looks like a leak to Analyze (and to me), so I'd like to resolve the problem. Anyone know what's going on here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload