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

时光怂恿深爱的人放手 提交于 2019-11-29 14:18:27

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20512671/app-terminated-due-to-memory-pressure-when-using-camera-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!