由于内存压力而终止应用程序

编程入门 行业动态 更新时间:2024-10-08 13:37:52
本文介绍了由于内存压力而终止应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个应用程序可以在Burst模式下拍摄图像,但是一旦拍摄图像并即将到来预览它会崩溃并且错误显示由于内存压力而终止应用程序

I have an app to take images in Burst mode ,but once when the image is take and about to come the preview its getting crashed and error shows that "Terminated App due to memory Pressure "

当用户拿着相机按钮时,我需要拍摄更多的图像...在离开按钮后,我需要将所有图像显示为幻灯片..我有什么要做什么?

I need to take more number of images when user holds the camera button...after Leave the button ,i need to show all the images as slideshow..what i have to do ?

我的代码是:

- (void)longPress:(UILongPressGestureRecognizer*)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takePictures) name:AVCaptureSessionDidStartRunningNotification object:nil]; } else if (gesture.state == UIGestureRecognizerStateEnded) { } -(void)takePictures { [imagePicker takePicture]; }

帮助我..

推荐答案

由于图像的高分辨率,将图像存储在RAM中的成本很高。更重要的是,你的观察者会多次调用takePicture - 太多了。当您使用imagePicker拍摄多张照片时,所有这些图像都会快速消耗RAM,而且由于iOS没有交换 - 因此RAM耗尽。然后Jetsam / memorystatus开始使用并杀死你的应用程序,因为已经耗费了大量内存。

Storing images in RAM is costly, due to the high resolution of the images. What more, your observer cause takePicture to be called multiple times - too many. As you take multiple pictures using the imagePicker, all these images quickly consume RAM, and since iOS has no swap - you run out of RAM. Jetsam/memorystatus then kicks in, and kills your app, for having consumed so much memory.

围绕这个方式:

A)在连拍模式下拍摄较少的照片。使用一些全局变量,比如j,在takePictures中递增它,但只取j%2 == 0或j%3 == 0的实际图片(你需要使用该值)

A) Take less pictures in burst mode. Use some global variable , say j, increment it in takePictures, but only take the actual picture on j % 2 == 0, or j %3 ==0 (you'll need to play around with the value)

B)尝试将至少一些照片保存到存储空间,然后从RAM中释放它们(删除对它们的引用)。

B) try to save at least some of the photos to storage, then release them from RAM (remove the reference to them).

更多推荐

由于内存压力而终止应用程序

本文发布于:2023-11-03 05:03:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   内存   压力

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!