开发者

Autorelease for CGMutablePathRef?

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?

Edit: For others who stumble upon t开发者_Python百科his question, the below advise is for C functions returning Core foundation objects only. For objective C methods returning Core foundation objects, see Ownership regarding to returned Quartz objects


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...);

Then you should rename it to:

CGMutablePathRef createMyAwesomePath(params...);

so that you are safe to return an object with a +1 retain count by following the Create rule.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜