title: Memory warning when saving image sequence
body: <p>I am attempting to convert a video to a sequence of image frames and save them to file. However after about 5 frames I get a memory warning and the application quits due to memory pressure soon after. The images are around 10kb in size. My code is below, what am i doing wrong?</p>
  
  <p>Thanks in advance, Ben.</p>
  
  <pre><code>-(void)framesFromVideo:(AVURLAsset *)asset{
      NSArray *times = [self timeSequenceFromAsset:asset];
  
      NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
      NSString *folderPath = rootPath;
  
      __block int i=0;
      generator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
      generator.apertureMode = AVAssetImageGeneratorApertureModeCleanAperture;
      generator.appliesPreferredTrackTransform = TRUE;
      generator.requestedTimeToleranceBefore = kCMTimeZero;
      generator.requestedTimeToleranceAfter = kCMTimeZero;
      [generator generateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
  
          if (result == AVAssetImageGeneratorSucceeded) {
              NSString *imgPath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", i]];
              [self writeImageRef:im toPath:imgPath];
          }else if (result == AVAssetImageGeneratorFailed){
              NSLog(@"Frame generation failed with error:%@", error);
          }else if (result == AVAssetReaderStatusCancelled){
              NSLog(@"Frame generation cancelled");
          }
          NSLog(@"Completed frame");
          i++;
      }];
  }
  </code></pre>