我使用CGBitmapContextCreate创建了一个上下文。 我是否需要使用CGContextRelease释放它? 在Objective-C中,答案是肯定的,但在Swift中呢?
谢谢!
我使用CGBitmapContextCreate创建了一个上下文。 我是否需要使用CGContextRelease释放它? 在Objective-C中,答案是肯定的,但在Swift中呢?
谢谢!
func StringByAddingTwoStrings(CFString!, CFString!) -> Unmanaged<CFString>!
CGBitmapContextCreate
具有类型签名
func CGBitmapContextCreate(...) -> CGContext!
不,你不需要调用CGContextRelease
。事实上,尝试这样做会导致以下错误:
'CGContextRelease'不可用:Core Foundation对象被自动内存管理。
CGContext
实例在Swift中是自动内存管理的。你可以从函数签名看出来:
func CGBitmapContextCreate(/* several parameters */) -> CGContext!
你需要自己释放的返回值看起来像:
func CGBitmapContextCreate(/* several parameters */) -> Unmanaged<CGContext>!
var imageRef = CGBitmapContextCreateImage(context); var image = UIImage(CGImage: imageRef)
我是否也应该释放imageRef? - user2732722