【发布时间】:2016-01-11 08:44:28
【问题描述】:
在一个应用程序中,我们使用以下函数创建一个组合多个图像的图像。
UIGraphicsGetImageFromCurrentImageContext
一开始我们并没有注意到这个问题,因为函数 UIGraphicsGetImageFromCurrentImageContext 被多次使用。但是当应用程序完成并开始测试时,我们注意到在某些情况下应用程序由于应用程序内存使用而崩溃。每次我们执行 UIGraphicsGetImageFromCurrentImageContext 都会占用一些内存。我们注意到,在我们的应用程序的某些部分,我们不得不多次调用该函数,这是问题浮出水面的时候。
此外,当从循环中调用以下函数“combineImages”完成时,内存使用量会显着下降。
您可以在下面找到导致问题的应用程序部分。
func combineImages() -> UIImage {
let imageSize = CGSizeMake(pageWidth ,pageHeight);
UIGraphicsBeginImageContextWithOptions(imageSize, false, 1.0);
let rectCombine = CGRectMake( 0, 0, imageSize.width, imageSize.height)
image1.drawInRect(rectCombine)
image2.drawInRect(rectCombine)
image3.drawInRect(rectCombine)
image4.drawInRect(rectCombine)
let combinedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return combinedImage
}
【问题讨论】: