Just updated to Xcode Beta 4, and noticed the following compiler error with my code below:
var path = CGPathCreateMutable()
...
CGPathRelease(path)
'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed
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?
The Working with Cocoa Data Types section of Using Swift with Cocoa and Objective-C says (emphasis mine):
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.
So yes, unless you have an Unmanaged
struct, this is correct and you don't have to worry about manually releasing the object.
来源:https://stackoverflow.com/questions/24900595/swift-cgpathrelease-and-arc