【问题标题】:With ARC turned on, is there a different between alloc/init and normal autorelease methods? [duplicate]打开 ARC 后,alloc/init 和普通的 autorelease 方法有什么不同吗? [复制]
【发布时间】:2013-06-09 06:37:47
【问题描述】:

在 iOS 的 Objective-C 中使用 ARC 时,这两者有什么不同?

NSMutableArray *anArray = [[NSMutableArray alloc] initWithArray:itemsArray];
appDelegate.wishlistItemsArray = anArray;

appDelegate.wishlistItemsArray = [NSMutableArray arrayWithArray:itemsArray];

appDelegate 中的属性是:

@property (nonatomic, strong) NSMutableArray *wishlistItemsArray;

【问题讨论】:

  • 仅供参考 - 另一种选择是:appDelegate.wishlistItemsArray = [itemsArray mutableCopy];

标签: ios objective-c automatic-ref-counting autorelease


【解决方案1】:

不。这些方法仅在返回值的内存管理语义上有所不同,ARC 会为您处理内存管理,它们可以在 ARC 程序中互换使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-10
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2016-02-18
    • 2015-10-16
    相关资源
    最近更新 更多