Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: CGPathRelease and ARC

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?

like image 544
Epic Byte Avatar asked Jul 23 '14 01:07

Epic Byte


1 Answers

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, 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.

So yes, unless you have an Unmanaged struct, this is correct and you don't have to worry about manually releasing the object.

like image 196
jtbandes Avatar answered Nov 19 '22 12:11

jtbandes