Swift: CGPathRelease and ARC

Just upgraded to Xcode Beta 4 and noticed the following compiler error with my code below:

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

"CGPathRelease" is not available: Core Foundation objects are automatically managed memory.

So just I just delete my release calls, and should everything be fine? Or is there something else I am missing? And are there any special cases that I should know about using ARC?

+8
memory-management ios automatic-ref-counting swift core-foundation
source share
2 answers

Working with Cocoa Partitions The data types in the section Using Swift with Cocoa and Objective-C say (emphasis mine):

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

...

When Swift imports APIs that were not annotated, the compiler cannot automatically control returned Core Foundation objects. Swift wraps Core Foundation return objects in an Unmanaged<T> structure.

So, if you don’t have an Unmanaged structure, that’s right, and you don’t have to worry about manually releasing the object.

+19
source share

The accepted answer says: yes, you do not need CGPathRelease at all.


Note. If you use Unmanaged<T> in your code, select the accepted answer .

0
source share

All Articles