AVcapture session slow launch after session restart AVcapture session slow launch after session restart ios ios

AVcapture session slow launch after session restart


I have encounter the same problem I have found this line is the main problem

[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];

Just remove the previewlayer from the super layer while deallocating and there is no memory issue. My deallocating function is as follow

 -(void)deallocSession{[captureVideoPreviewLayer removeFromSuperlayer];for(AVCaptureInput *input1 in session.inputs) {    [session removeInput:input1];}for(AVCaptureOutput *output1 in session.outputs) {    [session removeOutput:output1];}[session stopRunning];session=nil;outputSettings=nil;device=nil;input=nil;captureVideoPreviewLayer=nil;stillImageOutput=nil;self.vImagePreview=nil;}

i called this function before popping and pushing any other view. It solved my issue.


Removing session inputs and outputs seems to solve this problem for me

[captureSession stopRunning];for(AVCaptureInput *input in captureSession.inputs) {    [captureSession removeInput:input];}for(AVCaptureOutput *output in captureSession.outputs) {    [captureSession removeOutput:output];}


What worked for me was setting the previewLayer of type AVCaptureVideoPreviewLayer() as a weak variable, then in the stopCaptureSession() function I have:

func stopCaptureSession() {    self.previewLayer?.removeFromSuperlayer()    self.previewLayer = nil    self.captureSession.stopRunning()    for input in captureSession.inputs {        self.captureSession.removeInput(input)    }    for output in captureSession.outputs {        self.captureSession.removeOutput(output)    }}

It turned out all my problems were connected to the previewLayer