Swift: CGPathRelease and ARC

后端 未结 1 813
甜味超标
甜味超标 2021-01-17 21:21

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

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


        
1条回答
  •  -上瘾入骨i
    2021-01-17 21:58

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

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

    0 讨论(0)
提交回复
热议问题