I have the following code in Swift:
func cropToAlpha(image:CGImage) -> CGImage? {
let pixelDataProvider:CGDataProvider? = CGImageGetDataProvider(image)
if pixelDataProvider != nil {
let pixelData:CFData? = CGDataProviderCopyData(pixelDataProvider!)
The documentation for CGImageGetDataProvider and the documentation for CGDataProviderCopyData both say
You are responsible for releasing this object
The Swift programming guide talks about deinitialization but that's not the same as releasing an object.
Some Objective-C answers (e.g. How do I release a CGImageRef in iOS) suggest calling CFRelease
but if I try something like
CFRelease(pixelDataProvider)
then I get the compiler error
'CFRelease' is unavailable: Core Foundation objects are automatically memory managed
How do I honor the request in the documentation for CGImageGetDataProvider and CGDataProviderCopyData by releasing the resulting objects in Swift?
(N.B. Searching the web for 'Swift release' is tricky as the search results are awash with pages about releases of Swift)