核心映像和内存泄漏,迅速3.0 [英] Core Image and memory leak, swift 3.0
本文介绍了核心映像和内存泄漏,迅速3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题,我尝试在扩展名为3000x2000的某些图像上使用过滤器,当我这样做时,RAM上部和应用程序出现致命错误"didReceiveMemoryWarning".
i have problem i try use filter at some images which have extension 3000x2000 , when i do it RAM upper and app have fatal error the "didReceiveMemoryWarning".
func setFilters(images: [UIImage]) -> [UIImage] {
let filter = CIFilter(name: "CIColorControls")!
filter.setValue(2.0, forKey: kCIInputContrastKey)
let context = CIContext(options: nil)
var result = [UIImage]()
for img in images {
let newImage = autoreleasepool(invoking: { () -> UIImage in
filter.setValue(CIImage(image: img)!, forKey: kCIInputImageKey)
let ciImage = filter.outputImage!
let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
return UIImage(cgImage: cgImage!, scale: img.scale, orientation: img.imageOrientation)
})
result.append(newImage)
}
return result
}
推荐答案
这不是内存泄漏;那实际上是您使用了过多的内存.导致问题的原因不是CIFilter.事实是您试图将所有这些巨大的UIImage对象保留在单个数组中的内存中:
It's not a memory leak; it's that you are in fact using too much memory. And it's not the use of CIFilter that's causing the problem; it's the fact that you are trying to keep all of these huge UIImage objects in memory in a single array:
var result = [UIImage]()
// ...
result.append(newImage)
不要那样做.
这篇关于核心映像和内存泄漏,迅速3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文