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?
Thanks!
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?
Thanks!
On
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<CGContext>!
CFTypes are automatically managed unless explicitly specified as Unmanaged.
According to the documentation. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html
Unmanaged types will have the type signature
CGBitmapContextCreatehas the type signatureHence its managed automatically by swift.