title: UIImage release error - *** -[UIImage release]: message sent to deallocated instance
body: <p>I have come up with an error "<em>*</em> -[UIImage release]: message sent to deallocated instance". Here is what I am doing.</p>
  
  <pre><code>void imageFromPicture(AVPicture *pict, int width, int height)
  {
  CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
  CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, pict-&gt;data[0], pict-&gt;linesize[0]*height,kCFAllocatorNull);
  CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  CGImageRef cgImage = CGImageCreate( width, 
                              height, 
                              8, 
                              24, 
                              pict-&gt;linesize[0], 
                              colorSpace, 
                              bitmapInfo, 
                              provider, 
                              NULL, 
                              NO, 
                              kCGRenderingIntentDefault);
  CGColorSpaceRelease(colorSpace);
  UIImage *image = [UIImage imageWithCGImage:cgImage];
  CGImageRelease(cgImage);
  CGDataProviderRelease(provider);
  CFRelease(data);
  
  [ref_to_self display: image];
  [image release];
  }
  
  - (void) display:(UIImage*)image
  {
  self.ImageView.image = image;
  }
  </code></pre>
  
  <p>Now, the function imageFromPicture is being called continuously in an infinite loop, until some break condition. This is used to display a continuous sequence of images. This code works properly, but after all my images are displayed and the control returns back to the Operating System I get this error.</p>
  
  <p>Can somebody please tell me what wrong am I doing. I do not have much idea on objective C memory management.</p>