Memory Usage in UIImagePickerController

I’m diligently working on app #2, which includes the ability to use photos from your photo library (or the camera if your device has one) and I ran into some memory issues. If you repeatedly create and destroy UIImagePickerController instances, you’ll quickly run out of memory (after picking like, seven photos). Fortunately, a little digging around led to the solution. Essentially, it involves keeping one instance around and continually re-using it.

Oh, also, if you’re doing animation in your app, be sure to turn off the animation while you access the camera. Otherwise, the camera will be really, really slow; causing you to question whether or not your app idea is even feasible; leading to a looong sleepless night until you finally realize what you were doing wrong. Just sayin’…

I make mistakes so that you don’t have to.

5 Responses to “Memory Usage in UIImagePickerController”

  1. Danimal Says:

    Nice. Thanks for tips Mach!

  2. Harry Says:

    Aha…! Nice. Thank you very much for these tips!

  3. Mach Says:

    Glad to be of service! =)

  4. Tarun Sharma Says:

    Hello,

    Thanks for the tutorial. I am using UIImagePickerController from one of my application and facing very strange problem. When i select an image from library and display it in imageview the memory consumption become very high (from 2.5MB to 12.9 MB, incase i select heavy image) and never came down again. If i comment the line which display the image in imageview the memory does not rise up at all. Can you please help me on this as i m really struck on this issue.

    What i exactly do when selected image from imagepicker controller i saved it in application delegate UIimage type variable and then display it using setimage.

    Thanks
    Tarun sharma

  5. Mach Says:

    I don’t know what the problem is as I’ve got a similar issue with Holograms but I’m guessing that somehow the image getting set gets retained an extra time.