【发布时间】:2011-05-31 14:07:39
【问题描述】:
我使用下面的代码来绘制子图
UIImage* subIm = getSubImage( large, rect );
[subIm drawInRect:self.bounds];
其中getSubImage定义如下
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
代码正确吗?
“CGImageRelease”imref 是否安全?
有子“CGImageRetained”imref 吗?
我应该释放 subIm(如果我这样做会出错)吗?
subIm 是否包含在 autorelease-pool 中,如果包含,我怎么知道?
一般来说,可以检查一个对象是否包含在自动释放池中(用于调试目的)?
【问题讨论】:
-
不要不要致电
retainCount。返回的数字通常没有意义。
标签: iphone ios memory-management cgimage autorelease