在这种情况下我需要发布NSMutableDictionary吗?

时间:2011-09-22 22:10:17

标签: cocoa-touch nsmutabledictionary

在这种情况下我是否需要发布dictCellCollectionIndividual

- (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;

}

不使用objectForKey会增加保留计数吗?我不能释放它吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

不,它只是返回指向字典中保存的对象的指针;如果您计划在任何时间段内保留对象,则需要获取它的所有权,以便在此期间释放NSDictionary时对象将保持有效。在这种情况下,您需要确保在完成对象时releaseautorelease对象。如果您计划仅将其用作临时值(例如,作为NSLog调用的参数),则可能不必保留该对象,因此无需释放它。