在iOS 7中使用相机时,应用因内存压力而终止 [英] App Terminated due to Memory Pressure when using camera in iOS 7
问题描述
当我使用UIImagePickerController Camera捕获一些图像时,我面临由于内存压力 App终止的错误。
I am facing error App Terminated due to Memory Pressure when I capture some images using UIImagePickerController Camera.
我首先收到内存警告然后突然app崩溃了。这个问题在iOS 7中特别适用于iOS 6,它工作正常。
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.
有人知道为什么在使用相机的iOS 7中会出现此内存问题。
Does someone know why is this memory issue occuring in iOS 7 on using camera.
注意:我试图最小化RAM使用率,因为它也可能是造成此内存压力的原因。但仍然收到警告。
Note: I tried to minimize RAM usage because it may also be the reason for this memory pressure. But still getting warning.
推荐答案
我刚刚在类似帖子上发布了这个答案( iOS 7 UIImagePicker预览黑屏)。这就是我所说的:
I just posted this answer on a similar post (iOS 7 UIImagePicker preview black screen). Here's what I said:
大约5个月前,我的团队发现了UIImagePickerController的内存泄漏。每个实例化都以指数方式减慢app的速度(即第一个alloc-init延迟1秒,第二个延迟2秒,第三个延迟5秒)。最终,我们有30-60个延迟(类似于你遇到的情况)。
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).
我们通过继承UIImagePickerController并使其成为Singleton解决了这个问题。这样它只被初始化一次。现在我们的延迟很小,我们避免泄漏。如果子类不是一个选项,请在viewController中尝试一个类属性,只是懒得加载它。
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];
据我所知,这只是iOS 7中UIImagePickerController的一个问题。以前的版本似乎没事。
From what I could tell, this is just an issue with the UIImagePickerController in iOS 7. Previous versions seems to be fine.
这篇关于在iOS 7中使用相机时,应用因内存压力而终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!