1

While using UIImagePickerController for capturing images, I am running into memory issues. My use case requires me to capture up to 10 images at a time and when the user clicks the done button which is present in camera overlay, the images should be sent to the server and at the same time displayed in CollectionView on dismissing the UIImagePickerController instance.

On the capture of 10th image, I manually dismiss the picker and send the images to the server and display it in the collectionView. Since I am having some threshold count of images, I am using array to hold the images and I empty the array every time 'Done' button is clicked or the user captures the 10th images.

I initially thought, I ran into memory issues because of the collectionView displaying images which aren't resized and hence I resized the image and displayed in the collectionView.

Then after googling, I read that memory leaks could happen when resizing the image and I fixed it too but still I am running into memory issues and everytime at the same image count of around 45th image (Capturing 10 images for 4 times and then getting memory warning and crash after capturing around 5 images in the 5th time in iPad4). Then I commented all my code in didFinishPickingMediaWithInfo and my app is not doing any processing except just capturing the image and still I am getting memory warning around 45th image.

I don't know what the problem is. Does the UIImagePickerController caches the images it captures or something like that?

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
    //All code in this section is commented out and no processing is done in any part of the code with the images captured.
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • memory warning occur in two types -> 1. your imagesize is heavy 2. your device memory is low – Anbu.Karthik Oct 05 '17 at 07:44
  • The thing is I want to know how the memory warning is caused. If I am just capturing the image and doing nothing with it, how could I end up with memory warning. I am not writing the captured image to any memory location and I am not even processing the image like resizing it. Just continuously capture the image and do nothing in didFinishPickingMediaWithInfo. – Karthik Ragunath A Oct 05 '17 at 08:51
  • i think the problem isn't from the size of image or the file, but there's a retain cycle in your code. That's happen when there's 2 or more object holding the same reference.. – RoccoBerry Oct 05 '17 at 09:56
  • Even if there is a retain cycle ... since I am not doing anything with the captured image... What effect will the retain cycle have ... Does this mean that images present in the info dictionary of didFinishPickingMediaWithInfo gets retained in the memory ?... Since when multiple images are captured... didFinishPickingMediaWithInfo gets called multiple times before the picker gets dismissed, but I suppose since the info dictionary in didFinishPickingMediaWithInfo being a let constant will not get retained in memory ... am I missing something here ? – Karthik Ragunath A Oct 05 '17 at 10:51
  • Does the didFinishPickingMediaWithInfo delegate method in UIImagePickerController caches the image contents present in its info dictionary? If so, how to clear that cache ? – Karthik Ragunath A Oct 05 '17 at 14:48
  • This bug is not occuring in iPhones and iPads which have 2GB or more RAM .... even if if I take 100's of images in a single session – Karthik Ragunath A Oct 09 '17 at 06:44

1 Answers1

0

This seems to be an issue in iOS 10.3.3 ... Once I updated my old device to iOS 11, this issue no longer exists ... The below given stackoverflow discussion helped me to understand the problem ...

UIImagePickerController leaking memory after launch and during taking a picture. Makes app crash after taking more than a 100 pictures