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 .