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

Cocoa touch 在这种情况下,我需要发布NSMutableDictionary吗?,cocoa-touch,nsmutabledictionary,Cocoa Touch,Nsmutabledictionary,在这种情况下,是否需要释放dictCellCollectionIndividual - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... ... ... ... ... ... // Local declaration of dictCellCollectionIndividual NSMutableDiction

在这种情况下,是否需要释放
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
是否会增加保留计数?我不需要释放它吗


提前感谢。

不,它只是返回一个指向字典中保存的对象的指针;如果您计划将该对象保留一段时间,则需要获得该对象的所有权,这样,如果同时解除分配
NSDictionary
,该对象将保持有效。在这种情况下,您需要确保在处理完对象后
释放
自动释放
。如果您计划仅将其用作临时值(例如,作为
NSLog
调用的参数),则可能不需要保留对象,因此也不需要释放它