Question

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;     
}
Was it helpful?

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.

OTHER TIPS

I cannot see any memory leak in your code. As toast points out, Instruments isn't always accurate. This is mostly because even the code from the Apple Frameworks contains memory leaks, which are reported by Instruments too.

If you are using XCode 3.2 you can choose Build and Analyze from the Build menu which scans your code for errors normally undetected by the compiler. This will show you many possible memory leaks resulting from forgetting to release an object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top