0

While attempting to reduce computation time while detection faces using CIDetector I tried to reuse a single detector instance for multiple face detections, as recommended by Apple:

This class can maintain many state variables that can impact performance. So for best performance, reuse CIDetector instances instead of creating new ones.

All worked fine until I began processing thousands of photos. Now, from time to time I get a random exception EXC_BAD_ACCESS. This doesn't happen when I don't reuse the detector but instantiate a new one every time.

Some relevant code snippets:

@property (retain, nonatomic) CIDetector* faceDetector;

- (void)initialVals {
    NSDictionary *opts_context = @{kCIContextUseSoftwareRenderer: @NO};
    self.context = [CIContext contextWithOptions:opts_context];
    NSDictionary *opts = @{ CIDetectorAccuracy: CIDetectorAccuracyHigh,
                        CIDetectorTracking: @YES,
                        CIDetectorMinFeatureSize: @0.15
                      };
self.faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:self.context options:opts];

}

I'm not sure but this question may be related to CIDetector isn't releasing memory .

Community
  • 1
  • 1
Xyand
  • 4,470
  • 4
  • 36
  • 63

1 Answers1

1

Problem solved, at least partially by removing the flag CIDetectorTracking: @YES when creating the detector.

It eliminates the crash while compromising on functionality. Filed an official bug report.

Xyand
  • 4,470
  • 4
  • 36
  • 63