Autorelease for CGMutablePathRef?

我是研究僧i 提交于 2019-12-23 18:03:57

问题


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 this 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


回答1:


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.



来源:https://stackoverflow.com/questions/2819548/autorelease-for-cgmutablepathref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!