objective-c - ARC 相当于自动释放?

标签 objective-c clang automatic-ref-counting autorelease

如果我有这段代码,

+ (MyCustomClass*) myCustomClass
{
    return [[[MyCustomClass alloc] init] autorelease];
}

这段代码保证返回的对象是自动释放的。 这在 ARC 中相当于什么?

最佳答案

ARC 中没有等效项,因为您不需要自己做。 它会在幕后发生,你不能自己做。

你只需使用 -

+ (MyCustomClass*) myCustomClass
{
    return [[MyCustomClass alloc] init];
}

我建议你看一下2011年WWDC上的ARC介绍,因为它很简单。

看这里: https://developer.apple.com/videos/wwdc/2011/

正如电影中的那个人所说——

You don't have to think about it any more (almost)

关于objective-c - ARC 相当于自动释放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8292060/

相关文章:

ios - CFStream 类是否符合 IPV6 标准?我正在使用 CFStreamCreatePairWithSocketToHost 连接到套接字而不是低级套接字 api

c++ - 有什么方法可以知道哪些 header 自动包含在 C++ 中

ios - 为没有 GCC 的 Xcode 5 编译 FFMpeg?

ios - ld : -bundle and -bitcode_bundle cannot be used together

ios - 在下载时从 NSURLSessionDownloadTask 访问字节

ios - 使用 WatchKit 拍摄 Group 元素的快照并保存到相机胶卷

iOS 为库编写单元测试

cocoa - NSOutlineView(源列表)ARC 的 EXC_BAD_ACCESS 错误

objective-c - 删除 View 、ARC、与 Objective C 和 Swift 的差异

ios - dismissViewControllerAnimated 不会释放 viewcontroller