Swift:CGPathRelease和ARC [英] Swift: CGPathRelease and ARC
问题描述
刚刚更新到Xcode Beta 4,并注意到以下代码中出现以下编译器错误:
Just updated to Xcode Beta 4, and noticed the following compiler error with my code below:
var path = CGPathCreateMutable()
...
CGPathRelease(path)
'CGPathRelease'不可用:Core Foundation对象是
自动内存管理
'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed
所以我只是删除我的版本电话,一切都应该没问题?还是有更多我想念的东西?是否有任何特殊情况我应该注意ARC?
So do I simply just remove my release calls and everything should be fine? Or is there something more I'm missing? And are there any special cases I should be aware of with ARC?
推荐答案
使用Cocoa数据类型 使用Swift与Cocoa和Objective-C 说(强调我的):
从带注释的API返回的Core Foundation对象在Swift中自动进行内存管理 - 你做的不需要调用
CFRetain
,CFRelease
,或CFAutorelease
自己发挥作用。如果从自己的C函数和Objective-C方法返回Core Foundation对象,则使用CF_RETURNS_RETAINED
或CF_RETURNS_NOT_RETAINED 对它们进行注释
。
Core Foundation objects returned from annotated APIs are automatically memory managed in Swift—you do not need to invoke the
CFRetain
,CFRelease
, orCFAutorelease
functions yourself. If you return Core Foundation objects from your own C functions and Objective-C methods, annotate them with eitherCF_RETURNS_RETAINED
orCF_RETURNS_NOT_RETAINED
.
...
当Swift导入尚未注释的API时,编译器不能自动内存管理返回的Core Foundation对象。 Swift将这些返回的Core Foundation对象包装在 Unmanaged< T>
结构中。
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
结构,这是正确的,你不必担心手动释放对象。
So yes, unless you have an Unmanaged
struct, this is correct and you don't have to worry about manually releasing the object.
这篇关于Swift:CGPathRelease和ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!