ios - Swift:CGPathRelease 和 ARC

标签 ios memory-management swift automatic-ref-counting core-foundation

刚刚更新到 Xcode Beta 4,并注意到我的代码出现以下编译器错误:

var path = CGPathCreateMutable()
...
CGPathRelease(path)

'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed

那么我是否只需删除我的发布调用,一切就应该没问题了?还是我还缺少什么?对于 ARC,我应该注意什么特殊情况吗?

最佳答案

Working with Cocoa Data Types 使用 Swift 与 Cocoa 和 Objective-C 部分说(强调我的):

Core Foundation objects returned from annotated APIs are automatically memory managed in Swift—you do not need to invoke the CFRetain, CFRelease, or CFAutorelease functions yourself. If you return Core Foundation objects from your own C functions and Objective-C methods, annotate them with either CF_RETURNS_RETAINED or CF_RETURNS_NOT_RETAINED.

When Swift imports APIs that have not been annotated, the compiler cannot automatically memory manage the returned Core Foundation objects. Swift wraps these returned Core Foundation objects in an Unmanaged<T> structure.

所以是的,除非你有 Unmanaged struct,这是正确的,您不必担心手动释放该对象。

关于ios - Swift:CGPathRelease 和 ARC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37430172/

相关文章:

c++ - 当一个元素从两者之间移除时,STL<vector> 中会发生什么?

ios - 如何使用 Google autocomplete place api ios 获得特定于州的结果?

ios - 在 Swift 中以编程方式制作 UIButton

ios - 单个可重用 UIView 类沿着特定路径出现在多个 ViewController 上的最佳实践?

ios - Swift with Core Data 在我获取的字符串上得到一个 "Optional("")"?

iphone - 以编程方式创建 UITableViewCell 还是从 nib 加载一个更快?

ios - 使用 Swift 3 和 Alamofire 的 JSON url 在应用程序中没有显示任何内容

c - free() 是在所有深度还是仅在最高级别释放内存?

python - 我什么时候应该在 python 中使用 del?

ios - 在 swift 的嵌套闭包中正确放置捕获列表