(sorry for my english :-) I'm loading a custom UITableViewCell:
static NSString *CellIdentifier = @"ReminderCell";
ReminderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"Alloco nuova cella");
NSArray *objectsInNib = [[NSBundle mainBundle] loadNibNamed:@"ReminderCell" owner:nil options:nil];
for(id currentObject in objectsInNib)
{
if([currentObject isKindOfClass:[ReminderCell class]])
{
cell = (ReminderCell *)currentObject;
break;
}
}
} //fine caricamento cella dal Nib
return cell;
I'm setting the owner to nil because I have .m and .h for this cell, and want to have the outlet inside it's own files and not in the UITableViewController. It's working ok.
My question is about correct memory management in this situation.
I understand that loadNibNamed returns an autoreleased array. Moreover, I understand that the autorelease pool is drained at the end of the current loop. For this reason, there should be no need to retain my custom cell before returning it.
But, I've heard many times that you shuold assume that an autoreleased object is guaranteed to live only until the end of the method where the autorelease was sent. Assuming this, I should retain the cell immediately and then autorelease it:
cell = [[(ReminderCell *)currentObject] retain];
//code...
[cell autorelease];
return cell;
Is this correct or should I not worry about this? Thanks