Do you need to release CGContextRef in Swift?

前端 未结 2 1194
生来不讨喜
生来不讨喜 2020-12-31 07:23

I\'ve created a context using CGBitmapContextCreate. Do I need to release it using CGContextRelease? I know the answer is yes in Objective-C, but how about in Swift?

2条回答
  •  -上瘾入骨i
    2020-12-31 08:01

    No, you don't need to call CGContextRelease. In fact, trying to gives you this error:

    'CGContextRelease' is unavailable: Core Foundation objects are automatically memory managed

    CGContext instances are automatically memory managed in Swift. You can tell from the function signature:

    func CGBitmapContextCreate(/* several parameters */) -> CGContext!
    

    A return value you would need to release yourself would look like:

    func CGBitmapContextCreate(/* several parameters */) -> Unmanaged!
    

提交回复
热议问题