首页 > Swift中CGImage内存泄漏

Swift中CGImage内存泄漏

在Swift中用createCGImage创建了一个CGImage对象,想调用CGImageRelease将其释放,但Swift中去除了CGImageRelease这个函数,官方说明是ARC会自动释放CGImage对象。但调试过程中仍然出现了内存泄漏的问题Received memory warning.
具体代码如下:

    func getUIImage(output:CIImage)->UIImage{
        let context = CIContext(options: nil)
        let cgImage = context.createCGImage(output, fromRect: output.extent)
        
        return UIImage(CGImage: cgImage)
    }

这是为什么?


收到 memory warning 并不能确定就是 CGImage 没释放,你用检查内存泄露的工具检查一下先。
另外, UIImage 有接受 CIImage 的构造器,为什么要先转成 CGImage 然后再转成 UIImage 呢?

UIImage(CIImage: ciImg)
【热门文章】
【热门文章】