Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom UITableViewCell, autorelease and other method
    primarykey
    data
    text
    <p>(sorry for my english :-) I'm loading a custom UITableViewCell:</p> <pre><code>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; </code></pre> <p>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.</p> <p>My question is about correct memory management in this situation.</p> <p>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.</p> <p>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:</p> <pre><code>cell = [[(ReminderCell *)currentObject] retain]; //code... [cell autorelease]; return cell; </code></pre> <p>Is this correct or should I not worry about this? Thanks</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.
    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