In one application we are creating an image combining several images using following function.
UIGraphicsGetImageFromCurrentImageContext
At first we did not notice the problem because function UIGraphicsGetImageFromCurrentImageContext was used several times. But when application has been finished and when we started testing we noticed that under certain conditions application was crashing because of application memory usage. Every time we execute UIGraphicsGetImageFromCurrentImageContext it get some of the memory occupied. In some part of the our application we had to call that function lots of times this is when the problem has been surfaced, we noticed.
Besides, when calling following function "combineImages" from a loop is finished memory usage is going down significantly.
You can find part of the application causing the problem below.
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
}