开发者

UIImage Memory problems because of caching

I googled for the memory issue associated with UIImage and came across many threads talking about the problem but no real help or solution.

I know when we use -imageNamed: the object is being cached so it's better to use initWithData:. When we use drawRect: and UIGraphicsGetImageFromCurrentImageContext(), does the image goes to cache?

Also in the following code:

CGImageRef tmp = CGImageCre开发者_运维技巧ateWithImageInRect(imageToCrop.CGImage, clippedRect);    //pull the image from our cropped context    UIImage *cropped = [UIImage imageWithCGImage:tmp];//UIGraphicsGetImageFromCurrentImageContext();  
CGImageRelease(tmp);

Is caching takes place although there is no reference about this in the documentation? How do we release the memory that is getting consumed by the cache?


I'm not sure the answer to your first question, but as far as the second question in concerned, you should note that when you access the CGImage property of the UIImage, the entire image is loaded into memory. This is referenced in the documentation for the CGImage property.

If you are done with the image after use, you can simply call the release method on the UIImage in order to release the memory. If you want to keep it around but remove it from the cache, I can't think of any way other than to write the image to disk, release it and then create a new image using -initWithData:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜