我有一个由96个UIImages(1280*720(组成的数组,并对每个UIImage进行720*720裁剪,然后将新图像保存在一个新的数组中。
在这个功能之后,我的手机内存会增加到400 MB,而且不会被释放。我试过用自动释放池,但没有用。
我的裁剪功能有问题吗?或者为什么内存没有释放?
这是我的代码:
循环通过图像阵列并保存新裁剪图像的图像
裁剪函数
内存
避免使用UIGraphicsImageBeginWithContext
,使用UIGraphicsImageRenderer
,如下所示。
有关更多详细信息,请参阅此From(17:00 min(:https://developer.apple.com/videos/play/wwdc2018/416
let bounds = CGRect(x: 0, y: 0, width:720, height: 720)
let renderer = UIGraphicsImageRenderer(size: bounds.size)
let image = renderer.image { context in // Use this Image
// Drawing Code
Your_View.drawHierarchy(in: bounds, afterScreenUpdates: true)
}