在iOS 7中使用相机时,应用因内存压力而终止

时间:2021-10-25 15:01:45

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

当我使用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.

我先收到内存警告然后突然崩溃。这个问题在iOS 7中特别适用于iOS 6,它运行正常。

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

有人知道为什么在使用相机的iOS 7中会出现此内存问题。

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

注意:我试图最小化RAM使用率,因为它也可能是这种内存压力的原因。但仍然得到警告。

1 个解决方案

#1


5  

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

我刚刚在类似的帖子上发布了这个答案(iOS 7 UIImagePicker预览黑屏)。这就是我说的:

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).

大约5个月前,我的团队发现了UIImagePickerController的内存泄漏。每个实例化都以指数方式减慢app的速度(即第一个alloc-init延迟1秒,第二个延迟2秒,第三个延迟5秒)。最终,我们有30-60个延迟(类似于您正在经历的)。

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并使其成为Singleton解决了这个问题。这样它只被初始化一次。现在我们的延迟很小,我们避免泄漏。如果子类化不是一个选项,请在viewController中尝试一个类属性,然后像这样延迟加载它。

-(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.

据我所知,这只是iOS 7中UIImagePickerController的一个问题。以前的版本似乎没问题。

#1


5  

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

我刚刚在类似的帖子上发布了这个答案(iOS 7 UIImagePicker预览黑屏)。这就是我说的:

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).

大约5个月前,我的团队发现了UIImagePickerController的内存泄漏。每个实例化都以指数方式减慢app的速度(即第一个alloc-init延迟1秒,第二个延迟2秒,第三个延迟5秒)。最终,我们有30-60个延迟(类似于您正在经历的)。

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并使其成为Singleton解决了这个问题。这样它只被初始化一次。现在我们的延迟很小,我们避免泄漏。如果子类化不是一个选项,请在viewController中尝试一个类属性,然后像这样延迟加载它。

-(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.

据我所知,这只是iOS 7中UIImagePickerController的一个问题。以前的版本似乎没问题。