在这种情况下我需要释放 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
不会增加保留计数吗 我不需要释放它吗?
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,它只是返回一个指向字典中保存的对象的指针;如果您打算在任何时间段内保留该对象,则需要获得它的所有权,以便在
NSDictionary
被释放的同时该对象将保持有效。在这种情况下,您需要确保在使用完对象后release
或autorelease
该对象。如果您打算仅将其用作临时值(例如,作为NSLog
调用的参数),则可能没有必要保留该对象,因此也没有必要释放它。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
NSDictionary
is deallocated in the meantime. In this case, you'll need to make sure to eitherrelease
orautorelease
the object when you're done with it. If you're planning to use it only as a temporary value (say, as an argument to anNSLog
call), it's probably unnecessary to retain the object, and therefore unnecessary to release it.