Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Terminated due to Memory Pressure when using camera in iOS 7

I am facing error App Terminated due to Memory Pressure when I capture some images using UIImagePickerController Camera.

I receive memory warnings first and then suddenly app crashes. This issue is in iOS 7 specifically as in iOS 6 it is working fine.

Does someone know why is this memory issue occuring in iOS 7 on using camera.

Note: I tried to minimize RAM usage because it may also be the reason for this memory pressure. But still getting warning.

like image 681
Nishant Tyagi Avatar asked Dec 11 '13 07:12

Nishant Tyagi


1 Answers

I just posted this answer on a similar post (iOS 7 UIImagePicker preview black screen). Here's what I said:

About 5 months ago my team discovered a memory leak with UIImagePickerController. Each instantiation slowed down the app exponentially (i.e. first alloc-init had a 1 second delay, second had a 2 second delay, third had a 5 second delay). Eventually, we were having 30-60 delays (similar to what you're experiencing).

We resolved the issue by subclassing UIImagePickerController and making it a Singleton. That way it was only ever initialized once. Now our delay is minimal and we avoid the leak. If subclassing isn't an option, try a class property in your viewController and just lazy load it like so.

-(UIImagePickerController *)imagePicker{
    if(!_imagePicker){
        _imagePicker = [[UIImagePickerController alloc]init];
        _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
    return _imagePicker;
}

Then you can just call it later like:

[self presentViewController:self.imagePicker animated:YES completion:nil];

From what I could tell, this is just an issue with the UIImagePickerController in iOS 7. Previous versions seems to be fine.

like image 114
ebandersen Avatar answered Nov 14 '22 00:11

ebandersen