0

I'm using the iOS face detector on all possible orientations of an image like this

for (exif = 1; exif <= 8 ; exif++)
{
    @autoreleasepool {


    NSNumber *orientation = [NSNumber numberWithInt:exif];
    NSDictionary *imageOptions = [NSDictionary dictionaryWithObject:orientation forKey:CIDetectorImageOrientation];
    NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];

    glFlush();
    features = [self.detector featuresInImage:ciimage options:imageOptions];
    //features = [self.detector featuresInImage:ciimage];

    if (features.count > 0)
    {
        NSString *str = [NSString stringWithFormat:@"-I- found faces using exif %d",exif];
        [faceDetection log:str];
        NSTimeInterval duration = [NSDate timeIntervalSinceReferenceDate] - start;
        str = [NSString stringWithFormat:@"-I- facedetection total runtime is %f s",duration];
        [faceDetection log:str];
        self.exif=[[NSNumber alloc] initWithInt:exif];
        break;
    }
    else {
        features = nil;   
    }
    }

}

but it seems in the profiler that the memory is growing each time:

Not sure if this is true, and if so how to solve the issue

Sorted by overall bytes and still living

Detail of the category

The relevant code

Avba
  • 14,822
  • 20
  • 92
  • 192

1 Answers1

0

In your loop most of the objects are auto-release type the main issue seems to be that you are assigning new value to "features" in each loop and if the "if" statement is true you are not making it nil. Try doing this:

if(features.count > 0)
{
  /// your existing code here
  features = nil;
  break;

}
sher
  • 39
  • 2
  • I'm doing features= nil; before the return statement but still getting the memory usage – Avba Sep 12 '13 at 10:41
  • oh I see.... From your code it looks like that were doing it only in else statement. However, it would be better to do it in the end of if-statement as return won't be called until for loop is executing. – sher Sep 12 '13 at 10:48