只要我保留对UIImage
作为参数传递给这些函数中的任何一个的引用,每个与图像相关的操作导致的内存增加仍然存在。如果我重复调用这些函数(每次使用不同的实例UIImage
),内存使用量会增加,直到应用程序崩溃。
示例1:
static func memoryNotReleasedExample(image: UIImage) {
guard let cgImage = image.cgImage else { return }
let imageTranslationRequest = VNTranslationalImageRegistrationRequest(targetedCGImage: cgImage)
}
示例2:
static func memoryNotReleasedExample2(image: UIImage) {
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
guard let copy = UIGraphicsGetImageFromCurrentImageContext() else { return }
UIGraphicsEndImageContext()
}
为什么会这样?它是一个错误吗?有没有办法强制释放内存?