iOS-内存警告后应用程序崩溃-仪器未显示泄漏 [英] iOS - App crashing after Memory Warning - Instruments showing no leaks

查看:96
本文介绍了iOS-内存警告后应用程序崩溃-仪器未显示泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVCaptureSession的应用程序来显示来自设备相机的实时"视频流.我还使用AVCaptureVideoDataOutputSampleBufferDelegate方法从sampleBuffer捕获静止图像(UIImage),以便在视频仍在屏幕上显示时(使用OpenCV)处理这些图像.无论如何,这里有很多代码,远远超过我在这里可以粘贴的代码,但这实际上不是重点.

I'm working on an app, that's using an AVCaptureSession, to show the "live" video stream from the device camera. I also use the AVCaptureVideoDataOutputSampleBufferDelegate methods to capture still images (UIImage) from the sampleBuffer to work with these images while the video is still being displayed on the screen (using OpenCV). Anyway, there's a lot of code, much more than I could paste here, but that's actually not the point.

该应用程序将在几秒钟后显示内存警告,再过几秒钟后,将以静默方式崩溃.我尝试使用Instruments检查泄漏和内存分配,但是没有可疑的迹象,完全没有泄漏,并且内存使用量从未超过5MB(全部和活动字节).

The app will show up a memory warning after some seconds and some more seconds later, crash silently. I tried to use Instruments to inspect leaks and memory allocation, but there's nothing suspicious showing up, no leaks at all and memory usage is never going above 5MB (overall and live bytes).

我如何找出触发内存警告的原因?

How do I find out why the memory warning is triggered?

我试图向代码中添加一些有意的泄漏,这些泄漏将出现在Instruments中,因此它在理论上似乎是有效的...

I tried to add some intentional leaks to the code, which will show up in Instruments, so it seems to work in theory...

推荐答案

我只是找到了原因,尽管我不明白为什么Instruments不显示此信息...

I just found the reason, although I don't understand why Instruments doesn't show this...

我使用了[t performSelectorInBackground:sel withObject:[self imageFromSampleBuffer:sampleBuffer]];

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

方法.在我对此发表评论后,该应用程序将正常运行.所以这里的问题是,尽管我在选择器中使用了NSLock,但应用程序会为每个选择器生成越来越多的线程,直到达到内存限制.因此,这里的解决方案是在执行选择器之前使用锁,而不是在选择器方法内部使用锁.

method. After I commented that out, the app would run fine. So the problem here was, although I used a NSLock in the selector, the app would spawn more and more threads for each selector until the memory limit was reached. So the solution here is to use a lock before performing the selector, not inside the selector method.

感谢您的所有帮助.

这篇关于iOS-内存警告后应用程序崩溃-仪器未显示泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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