Odd UITableView height behavior with NSZombieEnabled

I am setting my height:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    CGFloat rowHeight = 0;

    if(indexPath.row == [self.items count]){ //more
        rowHeight = 50.0; //same as moreCell 
    }
    else{
        ChartlyCell *cell = (ChartlyCell*)[self tableView:tblView cellForRowAtIndexPath:indexPath];
        rowHeight = cell.totalHeight;
    }

    return rowHeight;   
}

Here is how cell.totalHeight is calculated:

-(float)totalHeight {
    float h = messageLabel.totalheight + 35;
    if(h < 68) h = 68;
    return h;
}

My simulator crashes with no debug errors when NSZombieEnabled = NO. Simulator runs fine when NSZombieEnabled = YES. Not sure how to resolve?

UPDATE: This is how I am building my initializing my cell:

cell = [[[ChartlyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier andDelegate:self andChartlyDelegate:self andChartlyObj:myChartlyObject]autorelease];

If I remove the autorelease, everything runs fine. I am still confused why?

Answers


See the Cocoa Memory Management Guide.

Assuming that cell is an instance variable, consider:

cell = [[[ChartlyCell alloc] initWithStyle:UITableViewCellStyleDefault
                           reuseIdentifier:CellIdentifier
                               andDelegate:self
                        andChartlyDelegate:self
                             andChartlyObj:myChartlyObject]autorelease];

This will cause cell to be reaped when the pool is drained, thus leaving cell pointed to a now-deallocated instance of ChartlyCell. If you want an object to stick around, it must be retained. A retain is implied by alloc and effectively undone by autorelease. Removing the autorelease keeps the object around.

The simulator should have barfed an error back with zombies enabled. Odd that it didn't. File a bug via http://bugreport.apple.com/ and attach a built copy of the crashing version of your application with a link to this SO question.


Need Your Help

What are the key differences in Firefox and Chrome App manifests

web-applications google-chrome-app firefox-os progressive-web-apps

Both FF and Chrome have started supporting progressive web apps using app manifest and service workers.