title: AVCaptureSession - Stop Running - take a long long time
body: <p>I use ZXing for an app, this is mainly the same code than the ZXing original code except that I allow to scan several time in a row (ie., the ZXingWidgetController is not necesseraly dismissed as soon as something is detected).</p>
  
  <p>I experience a long long freeze (sometimes it never ends) when I press the dismiss button that call </p>
  
  <pre><code>- (void)cancelled {
    //  if (!self.isStatusBarHidden) {
    //      [[UIApplication sharedApplication] setStatusBarHidden:NO];
    //  }
  
      [self stopCapture];
  
      wasCancelled = YES;
      if (delegate != nil) {
          [delegate zxingControllerDidCancel:self];
      }
  
  
  } 
  </code></pre>
  
  <p>with </p>
  
  <pre><code>- (void)stopCapture {
      decoding = NO;
  #if HAS_AVFF
  
  
      if([captureSession isRunning])[captureSession stopRunning];
      AVCaptureInput* input = [captureSession.inputs objectAtIndex:0];
      [captureSession removeInput:input];
      AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[captureSession.outputs objectAtIndex:0];
      [captureSession removeOutput:output];
      [self.prevLayer removeFromSuperlayer];
  
      /*
       // heebee jeebees here ... is iOS still writing into the layer?
       if (self.prevLayer) {
       layer.session = nil;
       AVCaptureVideoPreviewLayer* layer = prevLayer;
       [self.prevLayer retain];
       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 12000000000), dispatch_get_main_queue(), ^{
       [layer release];
       });
       }
       */
  
      self.prevLayer = nil;
      self.captureSession = nil;
  #endif
  }
  </code></pre>
  
  <p>(please notice that the dismissModalViewController that remove the view is within the delegate method)</p>
  
  <p>I experience the freeze only while dismissing only if I made several scans in a row, and only with an iPhone 4 (no freeze with a 4S)</p>
  
  <p>Any idea ?</p>
  
  <p>Cheers</p>
  
  <p>Rom</p>