在这种情况下我需要释放 NSMutableDictionary 吗?

发布于 2024-12-06 07:42:34 字数 802 浏览 0 评论 0原文

在这种情况下我需要释放 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2024-12-13 07:42:34

不,它只是返回一个指向字典中保存的对象的指针;如果您打算在任何时间段内保留该对象,则需要获得它的所有权,以便在 NSDictionary 被释放的同时该对象将保持有效。在这种情况下,您需要确保在使用完对象后releaseautorelease该对象。如果您打算仅将其用作临时值(例如,作为 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 either release or autorelease 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 an NSLog call), it's probably unnecessary to retain the object, and therefore unnecessary to release it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文