When to release the UIImage ?
Posted
by
ragnarius
on Stack Overflow
See other posts from Stack Overflow
or by ragnarius
Published on 2010-12-28T13:21:46Z
Indexed on
2010/12/28
18:54 UTC
Read the original article
Hit count: 263
I use the following code to draw a subimage
UIImage* subIm = getSubImage( large, rect );
[subIm drawInRect:self.bounds];
where getSubImage
is defined as follows
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
Is the code correct?
Is it safe to "CGImageRelease" imref?
Has sub "CGImageRetained" imref?
Should I release subIm (I get an error if I do)?
Is subIm contained in the autorelease-pool, and , if so, how do I know this?
In general, can one check if an object is contained in the autorelease pool (for debugging purpose)?
© Stack Overflow or respective owner