1

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 

  }
Hope
  • 2,096
  • 3
  • 23
  • 40
  • Possible duplicate of [UIGraphicsGetImageFromCurrentImageContext memory leak with previews](http://stackoverflow.com/questions/5121120/uigraphicsgetimagefromcurrentimagecontext-memory-leak-with-previews) – Cœur Dec 24 '16 at 05:53

1 Answers1

0

We found out that function

    func combineImages()

was almost innocent for our memory problem. When we are trying to pinpoint issue about that function, we change the place where we call that function.

We were calling this function from our movie creation loop just before adding the new image to movie.

Now we are creating images using combineImages before movie creation loop started.

When we have been creating combined images we noted that there is no memory usage increase at all.

Besides, the memory usage increase when creating movie file is reduced.

Hope
  • 2,096
  • 3
  • 23
  • 40
  • I would like to add a comment. When _combineImages()_ is called from a loop the same memory problem is occurred for us. So we used a timer action to call function. – Hope Jan 13 '16 at 08:39