title: NSBitmapImageRep:colorAtX:y returned NSColor keeps growing on the heap
body: <p>I'm comparing the "color distance" between two images with the same width and height to see how similar they are - the measure of similarity is just comparing them pixel by pixel and seeing how far each of their color channels are from one another.</p>
  
  <pre><code>- (NSNumber*) calculateFitness:(NSImage*)currentImage 
                andDestinationImage:(NSImage*)destinationImage {
  NSData  *tiffData = [currentImage TIFFRepresentation];
  NSBitmapImageRep *currentImageRep = [NSBitmapImageRep 
                                       imageRepWithData:tiffData];
  
  NSData *destinationImageTiffData = [destinationImage TIFFRepresentation];
  NSBitmapImageRep *destinationImageRep = [NSBitmapImageRep  imageRepWithData:destinationImageTiffData];
  
  long fitnessScore = 0;
  
  for (int width = 0; width &lt; currentImageRep.size.width; width++) {
      for (int height = 0; height &lt; currentImageRep.size.height; height++) {
          NSColor *destinationColor = [destinationImageRep colorAtX:width y:height];
          NSColor *currentColor = [currentImageRep.size.height colorAtX:width y:height];
  
          CGFloat deltaRed = (currentColor.redComponent - destinationColor.redComponent) * 255;
          CGFloat deltaGreen = (currentColor.greenComponent - destinationColor.greenComponent) * 255;
          CGFloat deltaBlue = (currentColor.blueComponent - destinationColor.blueComponent) * 255;
  
          fitnessScore += (deltaRed * deltaRed) +
                          (deltaGreen * deltaGreen) +
                          (deltaBlue * deltaBlue);
  
          }
      }
  }
  </code></pre>
  
  <p>I call this method many many times in my program to compare the fitness of thousands of images to one another. What I'm noticing in instruments is that the number of living NSCalibratedRGBColor objects keeps growing and it's due to the <code>destinationColor</code> and <code>currentColor</code> objects being created with <code>NSBitmapImageRep:colorAtX:y</code> above. Eventually, my entire system memory will be consumed.</p>
  
  <p>So - is there a reason why this happens? What am I doing wrong? Is there a more efficient way to get the raw bitmap data for my images? </p>
  
  <p>Thanks<br>
  Mustafa</p>