Search code examples
objective-ciphone-sdk-3.0memory-leaksinstruments

Where's the memory leak here?


Instruments tells me there's a mem leak in this code, but I can't seem to find it....any help? sorry or the newbie question.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int altoBufferCelda = 26;
    Mensaje *msg = (Mensaje *)[model.mensajes objectAtIndex:indexPath.row];

    CGSize txtSize = [msg.texto sizeWithFont:[UIFont systemFontOfSize:17.0f] constrainedToSize:CGSizeMake(222, 222)  lineBreakMode:UILineBreakModeTailTruncation];

    [alturasDinamicas setObject:[NSNumber numberWithFloat:(txtSize.height + altoBufferCelda)] forKey:[NSNumber numberWithInt:indexPath.row]];

    return txtSize.height + altoBufferCelda;     
}

Solution

  • I would say: [NSNumber numberWithFloat]

    It will allocate an autoreleased object for you. The iPhone isn't garbage collected, just reference collected. And since you aren't releasing the memory you are allocating before you leave the method, Instruments is reporting it as a leak.

    Since this is currently accepted, I'll kind of change my answer.

    Instruments isn't a divine edict. It could be wrong. Use it as a strong guideline of what you should be looking at, but if you honestly cannot find anything wrong or leaky with the code, just move on.