Search code examples
iosswiftuiimagepickercontroller

memory warning UIImagePickerController


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.
}

Solution

  • 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