刚刚更新到
Xcode Beta 4,并注意到以下编译器错误,我的代码如下:
var path = CGPathCreateMutable() ... CGPathRelease(path)
‘CGPathRelease’ is unavailable: Core Foundation objects are
automatically memory managed
所以,我只是删除我的发布呼叫,一切都应该没问题?还是有更多我想念的东西? ARC有什么特殊情况需要注意吗?
解决方法
使用Swift与Cocoa和Objective-C的
Working with Cocoa Data Types部分说(强调我的):
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
.…
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.
所以,是的,除非你有一个非托管结构,这是正确的,你不必担心手动释放对象.