tags:

views:

313

answers:

2

I read a few memory-leaking issues with UIImagePickerController, so I changed my code to using member variable and was able to take more than a few pictures with the camera. However, I find the photo-taking to take longer and longer time, and eventually it crashed at around 25 photos.

There are two things I do after the photo in the didFinishPickingMediaWithInfo,

1) scale the image down and display that (50x50) 2) save a 320x460 to CoreData

I didn't release any UIImage since it's on the autorelease pool.

What should I do to let the picture-taking go on forever?

Below is the crash log (Type of crash log is listed as Low Memory)

CrashReporter Key:   8e197e26271ae3c2c4d3e725807d023e3c2354cb
OS Version:          iPhone OS 3.0 (7A341)

Free pages:        251
Wired pages:       10127
Purgeable pages:   0
Largest process:   Journal

Processes
         Name                 UUID                    Count resident pages
         Journal     8960 (jettisoned) (active)
     debugserver      130
     MobilePhone      529 (jettisoned)
    syslog_relay       53
notification_pro       54
      DTMobileIS     2285
notification_pro       53
            ptpd      276
    mediaserverd      252
     debugserver       77
     debugserver       78
     SpringBoard     2470 (active)
         notifyd       80
        BTServer      123
      CommCenter      262
      accessoryd       84
         configd       70
         configd      266
       fairplayd       67
   mDNSResponder       89
       lockdownd      252
         syslogd       82
         launchd       70

A: 
  • Can you provide backtrace / more crash information?
  • Is it possible to manage the UIImages yourself, or wrap the call that gives you an autoreleased UIImage with your own NSAutoreleasePool so you can control its lifetime?
  • Have you tried using Instruments to detect for any possible memory leaks?
fbrereto
I don't have any backtrace, basically the app quit because of low memory issue according to crash log and the app is jettisoned.
Boon
The crash log should have the backtrace in it; can you post it?
fbrereto
Crash log is attached.
Boon
Thanks; what about answers to my other two questions?
fbrereto
To your questions:Yes it's possible to manage the UIImage myself. The UIImage I got in the finish delegate was basically scaled down and saved to CoreData right away. A thumbnail version of it is also displayed as preview.I am having problem running instrument since I upgraded to Snow Leopard. I have laid out the issue in another SO post.
Boon
A: 

This question is pretty old, so hopefully already solved but consider 2 points:

  1. CoreData is a terrible place to save BLOBS, it's really good at text but not so much for binary data.
  2. Your image will live in memory until you give it some place else to go, the only way to get them out of memory is releasing all references to that data.

I would consider caching your images to the file system until they are required again. Basically follow this process:

  • Capture Image1
  • Want to take another? Capture Image2 and write Image1 out to disk.
  • Store the filename for Image1 in CoreData for later retreival.

Repeat as necessary.

It is still possible that you will run out of disk space eventually, but you will have a lot more available disk space than memory, and you can always purge unwanted images from disk or force your user to deal with them in some other convenient manner (upload to the cloud for example).

ImHuntingWabbits