views:

45

answers:

1

Hi,

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 http://stackoverflow.com/questions/2901942/ownership-regarding-to-returned-quartz-objects

+2  A: 

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.

Dave DeLong
By `CHMutablePathRef` do you mean `CGMutablePathRef`?
KennyTM
@KennyTM whoops! Fixed.
Dave DeLong