AVCaptureSession没有任何理由得到内存警告和崩溃 [英] AVCaptureSession get Memory warning and crash with no reason

查看:162
本文介绍了AVCaptureSession没有任何理由得到内存警告和崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款操作高清照片的应用。我正在用AVCaptureSession拍照,停下来然后在那张照片上应用效果。

I am working on an app that manipulates HD photos. I am taking a photo with an AVCaptureSession, stopping it and then apply effects on that photo.

让我疯狂的事情是一切正常,乐器告诉我我按时正确地释放了我使用的所有内存。它真的很高,有时达到100mb。但它很快就会崩溃。

The thing that makes me CRAZY is that everything works fine, instruments tells me that I release all the memory I use properly and on time. It goes really high yes, sometimes to 100mb. But it goes down quickly.

然后我重启我的Capture Session并得到一个内存警告。绝对没有理由; _;我释放时使用的所有内存...然后下次我将重新启动捕获会话时应用程序崩溃。没有消息,没有日志,什么都没有。

Then I restart my Capture Session and I got a memory warning. There is absolutely no reason for that ;_; All the memory I used if freed... Then the next time I will restart the capture session the app crashes. No messages, no logs, nothing at all.

我不知道如何解决这个问题,我不知道在哪里寻找...如果有人可以帮助我一点点我会很高兴!

I don't know how to solve this, I don't know where to look for... If someone could help me a little bit I would be so glad!

提前致谢!

推荐答案

我有同样的挫败感。我在一个项目中使用ARC,我正在使用AV Foundation展示相机。在呈现并弹出视图控制器几次后,我的应用程序将收到低内存警告,并随后崩溃。仪器也没有多大帮助。我通过试验发现了解决方案:

I've had the same frustrations. I was using ARC in a project where I was presenting a camera using AV Foundation. After presenting and popping the view controller a few times, my app would receive a low memory warning, and subsequently crash. Instruments didn't help much either. I discovered the solution by experimenting:

即使您在相机类中使用ARC,也可以实现dealloc方法(只是不要调用 dealloc上的超级

Even though you are using ARC in your camera class, you can implement the dealloc method (just don't call super on dealloc).

- (void)dealloc {
    AVCaptureInput* input = [session.inputs objectAtIndex:0];
    [session removeInput:input];
    AVCaptureVideoDataOutput* output = [session.outputs objectAtIndex:0];
    [session removeOutput:output];  
    [session stopRunning];
}

这样可以停止AVCaptureSession并确保它没有输入或输出活着。

This takes care of stopping the AVCaptureSession and ensuring it has no inputs or outputs still alive.

这篇关于AVCaptureSession没有任何理由得到内存警告和崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆