title: NSImage TIFFRepresentation doesn't get released with ARC
body: <p>I have an OSX Cocoa ARC project that handles thousands of images.  In order to reduce the number of images, we scan the images to see if they are a uniform color, and if so, we discard the image and keep track of its color.</p>
  
  <p>The code to get a solid color is:</p>
  
  <pre><code>- (NSColor *)getSolidColor:(NSImage *)image
  {
  NSBitmapImageRep* raw_img = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
  
  int Bpr = [raw_img bytesPerRow],spp = [raw_img samplesPerPixel];
  unsigned char *data = [raw_img bitmapData];
  int w = [raw_img pixelsWide],h = [raw_img pixelsHigh];
  
  uint32_t mask = 0x00FFFFFF;
  uint32_t color = *((uint32_t *)data) &amp; mask;
  
      for( int y=0; y&lt;h; y++ ) 
      {
      unsigned char *p = data + Bpr*y;
  
          for( int x=0; x&lt;w; x++ ) 
          {
              if( color != (*((uint32_t *)p) &amp; mask) )
                  return( nil );
              p += spp;
          }
      }
  
      return( [raw_img colorAtX:0 y:0] );
  }
  </code></pre>
  
  <p>(Some error checking removed for brevity - above code assumes 3 samples per pixel.)</p>
  
  <p>The code that calls it is basically:</p>
  
  <pre><code>NSString *imageFile;
  while( imageFile = [self getNextImageFile] )
  {
  NSImage *image = [[NSImage alloc] initWithContentsOfFile:imageFile];
      if( [image isValid] &amp;&amp; [self getSolidColor:image] )
          [fileManager removeItemAtPath:imageFile error:nil];
  }
  </code></pre>
  
  <p>The problem is that the application consumes an exraordinary amount of memory.  When I run it in the profiler, it indicates that 90% of the memory used is being allocated by [NSImage TIFFRepresentation] (bolded above.)  </p>
  
  <p>i.e. The TIFFRepresentation data and NSBitmapImageRep are never freed even though they fall out of scope as soon as the function returns.</p>
  
  <p>Why?  And what should/can I do to force ARC to release those blocks?</p>
  
  <p>With the 'old way' using non-ARC I would just put an autorelease pool inside the while loop for the images and that would take care of the problem.  Is there such a concept with ARC?</p>
  
  <p>Thanks.</p>
  
  <p>(PS. NSZombies is NOT enabled.)</p>