AVCaptureSession get Memory warning and crash with no reason

后端 未结 2 1915
萌比男神i
萌比男神i 2020-12-24 15:00

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.

The thing that mak

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 15:56

    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:

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

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

提交回复
热议问题