问题描述
我缩放一个CGImageRef。我在网上找到了如下开始的各种代码示例:
CGColorSpaceRef colorspace = CGImageGetColorSpace //Getcolorspace
CGContextRef context = CGBitmapContextCreate(NULL,width,height,
CGImageGetBitsPerComponent(image),
CGImageGetBytesPerRow(image),
colorpace,
CGImageGetAlphaInfo (图片));
CGColorSpaceRelease(colorspace); //真的吗?
如上所示, colorspace
发行了。然而,当我这样做,我的代码工作大部分时间,但崩溃了一段时间,因为有时,颜色空间实例已经走了。 API文档说:
这是否意味着我必须发布?我假定约定是,只有在名称中返回 create
的结果才会返回明确释放的对象。这是否意味着网络上的例子在发布色彩空间时是完全错误的?
谢谢你,Mark。
如API文档所述,您需要负责保留并释放必要的颜色空间。也就是说如果你需要,保留它。如果你不保留,不要释放。
p>
I'm scaling a CGImageRef. I found various code examples on the web that begin like so:
CGColorSpaceRef colorspace = CGImageGetColorSpace(image); // "Get" colorspace
CGContextRef context = CGBitmapContextCreate(NULL, width, height,
CGImageGetBitsPerComponent(image),
CGImageGetBytesPerRow(image),
colorspace,
CGImageGetAlphaInfo(image));
CGColorSpaceRelease(colorspace); // Really?
As you can see above, the colorspace
is released. However, when I do that my code works most of the time, but crashes once in a while, because sometimes that colorspace instance is already gone. The API docs say:
Does that mean I must release it? I assumed the convention was that only results of calls with "create
" in the name return objects that have to be released explicitly. Does this mean the examples on the web are simply wrong when releasing that colorspace?
Thanks, Mark.
As the API docs say, you are responsible for retaining and releasing the color space as necessary. I.e. if you need, retain it. If you do not retain, don't release.Read more about it here
这篇关于CGImageGetColorSpace(image)的结果是否必须释放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!