Terminated App due to memory Pressure

2019-04-10 06:57发布

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 ?

My code is:

- (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];
}

Help me..

1条回答
Melony?
2楼-- · 2019-04-10 07:48

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.

Ways around this:

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) try to save at least some of the photos to storage, then release them from RAM (remove the reference to them).

查看更多
登录 后发表回答