views:

186

answers:

2

Occasionally in low-memory conditions the UIImagePickerController I use gets 'stuck' with the shutter closed. Generally when this the WatchDog is allready jettisoning other background apps so within a second or two the low memory condition is over, yet the UIImagePicker controller is still stuck.

Has anyone else encountered this and implemented any sort of workaround or found a way to detect when the picker is in this state, so that it can be removed and a new one put in its place.

Thoughts / Ideas / Solutions??

A: 

That's a known behavior of the camera application too. I guess you can't do anything to it except freeing as much memory as you can before starting it. You could raise a memoryWarning yourself so every application will receive it and start freeing memory but I have no idea how I can do that. I started investigate sending the notification myself (UIApplicationDidReceiveMemoryWarningNotification) without success. I guess we need to send an object along the notification to define the warning level but I'm really not sure.

VdesmedT
You can't raise a system warning notification yourself--`UIApplicationDidReceiveMemoryWarningNotification` is the notification that is internal to your application only.
rpetrich
@rpetrich : Thank you !
VdesmedT
+2  A: 

Have you tried allocating (and then freeing) a megabyte or two of memory using malloc() before starting the UIImagePicker? Or claim it slightly earlier in your app, and then release it when you want to show the picker.

I guess you should be able to see roughly the amount of memory UIImagePicker needs to run successfully by running your app inside of instruments.

Whilst not ideal, it should cause other apps to be given memory warnings earlier on and hence the UIImagePicker should then have enough memory to run.

JosephH
If you use a repeating NSTimer to schedule the a bunch of mallocs in fractional size chunks over several milliseconds, it will allow more time for the memory warnings to clean up the memory usage of any other background apps. Then free all of this just before calling the image picker.
hotpaw2
@hotpaw2: Yep, that's probably a good idea, thanks! I think I'd made the blocks fairly large (and probably not smaller than the largest block UIImagePicker requires), as there is a risk of introducing fragmentation into the application's heap otherwise.
JosephH
I have played around with that a bit. Strangley enough, simply doing an alloc
Brad Smith
I think something may have eaten half of your last sentence unfortunately! :(
JosephH