问题描述
我正在为iPhone开发。我想通过CGPathCreateMutable()创建一个可变路径,并且要将其从创建它的函数中返回。我想在完成后调用CGPathRelease()。但是由于我要退货,所以我希望将其自动释放。由于Quartz路径是C代码(并且看起来不像目标C对象),因此我不能在其上调用自动释放是否正确?
I am developing for iphone. I want to creating a mutable path via CGPathCreateMutable(), and I want to return it out of the function which creates it. I'm suppose to call a CGPathRelease() when I'm done with it. But since I'm returning it I wish to autorelease it. Since Quartz path is a C code (and doesn't look like an objective C object), is it correct that I cannot call autorelease on it?
编辑:
对于其他偶然发现此问题的人,以下建议仅适用于返回Core基础对象的C函数。有关返回Core基础对象的客观C方法,请参见
推荐答案
正确。自动释放池存在于Foundation层及以上(AppKit / UIKit等)中。对于CoreFoundation / CoreGraphics对象,它们不存在。
Correct. Autorelease pools exist in the Foundation layer and above (AppKit/UIKit, etc). They don't exist for CoreFoundation/CoreGraphics objects.
解决此问题的简单方法是重命名函数。如果您的函数当前被命名为:
The simple way around this is to rename your function. If your function is currently named:
CGMutablePathRef myAwesomePath(params...);
然后应将其重命名为:
CGMutablePathRef createMyAwesomePath(params...);
这样您就可以安全地通过按。
so that you are safe to return an object with a +1 retain count by following the Create rule.
这篇关于自动发布CGMutablePathRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!