Do I need to release dictCellCollectionIndividual in this case?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
... ...
... ...
... ...
// Local declaration of dictCellCollectionIndividual
NSMutableDictionary *dictCellCollectionIndividual;
// Copy the specific dictionary from dictCellCollection to dictCellCollectionIndividual. dict CellCollection is declared elsewhere.
dictCellCollectionIndividual = [dictCellCollection objectForKey:[NSString stringWithFormat:@"%@", [arrayCellCollectionOrder objectAtIndex:indexPath.row]]];
... ...
... ...
... ...
// Do I need to release?
[dictCellCollectionIndividual release];
return cell;
}
Doesn’t using objectForKey increase the retain count? Don’t I have to release it?
Thanks in advance.
No, it simply returns a pointer to the object held within the dictionary; if you plan to keep the object around for any period of time, you need to take ownership of it, so that the object will remain valid if
NSDictionaryis deallocated in the meantime. In this case, you’ll need to make sure to eitherreleaseorautoreleasethe object when you’re done with it. If you’re planning to use it only as a temporary value (say, as an argument to anNSLogcall), it’s probably unnecessary to retain the object, and therefore unnecessary to release it.