CGImageRelease in Swift

Jean Lebrument picture Jean Lebrument · Sep 11, 2014 · Viewed 7.6k times · Source

In Objc I use CGImageRelease method after the treatment of an image. But in Swift this method is not available.

On the Apple documentation after Retaining and Releasing Images there is a 2 Objective-C symbols hidden

My question is, why is there no more CGImageRelease in Swift ? And have we to call another method to replace it ?

Thanks !

Answer

Rob Napier picture Rob Napier · Sep 11, 2014

CGImage is now managed by ARC. CGImageRelease() is no longer required on it. You can know this by looking in CGImage.h and noting that it includes the macro CF_IMPLICIT_BRIDGING_ENABLED. This indicates that Apple has audited this file to make sure it conforms to memory-management naming conventions so ARC can memory manage objects returned from functions in this file.


EDIT: I was reading over this and realized I was misleading. I don't mean to say that CGImageRelease isn't needed in ObjC (which is pretty much what I implied here…) I just mean that because of the auditing, Swift is able to handle it. In ObjC code, you still need to release these objects.