I'm still shaky on the subtler aspects of memory management, and I have a question about the aggressive retaining/releasing I've seen in some sample code. Specifically:
- (void)loadContentForVisibleCells
{
NSArray *cells = [self.tableView visibleCells];
[cells retain];
for (int i = 0; i < [cells count]; i++)
{
// Go through each cell in the array and call its loadContent method if it responds to it.
FlickrCell *flickrCell = (FlickrCell *)[[cells objectAtIndex: i] retain];
[flickrCell loadImage];
[flickrCell release];
flickrCell = nil;
}
[cells release];
}
Why the [retain/release] cycle on the FlickrCell (lines 8 & 10)? The cell is in an NSArray which by definition has retained its contents (I think...?), and the NSArray itself is retained. Why would this additional retain be necessary?
Furthermore, why the retain on the NSArray returned by [self.tableView visibleCells] (line 3)? Isn't the array guaranteed to be around for the duration of this method call?
Thanks very much.