title: When to release the UIImage?
body: <p>I use the following code to draw a subimage</p>
  
  <pre><code>UIImage* subIm = getSubImage( large, rect );
  [subIm drawInRect:self.bounds];
  </code></pre>
  
  <p>where <code>getSubImage</code> is defined as follows</p>
  
  <pre><code>    UIImage* getSubImage(UIImage* uim, CGRect rc){
        CGImageRef imref  = CGImageCreateWithImageInRect(uim.CGImage, rc); 
        UIImage*   sub = [UIImage imageWithCGImage:imref];
        CGImageRelease(imref);
          NSLog(@"subimage retainCount=%d", [sub  retainCount]); // is 1
        return sub;
     }//getSubImage
  </code></pre>
  
  <p>Is the code correct?</p>
  
  <p>Is it safe to "CGImageRelease" imref?</p>
  
  <p>Has sub "CGImageRetained" imref? </p>
  
  <p>Should I release subIm (I get an error if I do)?</p>
  
  <p>Is subIm contained in the autorelease-pool, and , if so, how do I know this?</p>
  
  <p>In general, can one check if an object is contained in the autorelease pool (for debugging purpose)?</p>