Re: ARC + return of autoreleased CFType
Re: ARC + return of autoreleased CFType
- Subject: Re: ARC + return of autoreleased CFType
- From: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 21 Oct 2011 00:38:57 +0200
Le 20 oct. 2011 à 23:38, Bill Cheeseman a écrit :
>
> On Oct 20, 2011, at 4:43 PM, Matt Neuburg wrote:
>
>> Sure, but still, he's returning a retained CGColorRef. And CGColor participates in this convention (CGColorRelease, CGColorRetain, CGColorCreate etc.). I'm not saying he has to do it; I'm merely suggesting that the magic word "Create" will help him remember what he's trying to remember, namely that he's returning a retained CGColorRef and the caller will need to call CGColorRelease on it later.
>
>
> You're absolutely right, Matt. But it's actually more fundamental than that, now that Xcode 4 has the Analyze command. I don't believe this is documented, but I found out by trial and error that the Core Foundation "create rule" should be followed in Cocoa methods that return Core Foundation CFTypeRef objects, if you want to get optimum results from Analyze.
>
> Specifically, if your Cocoa method returns a CFTypeRef object retained, and you don't put "Copy" or "Create" in the method name, Analyze reports a "potential" memory leak. Go back and insert "Copy" or "Create" into the method name, and Analyze no longer reports a potential memory leak. To me, it makes all the sense in the world to apply the "create rule" to Cocoa methods that return Core Foundation CFTypeRef objects.
>
> I found this discovery extraordinarily helpful in using Analyze to kill memory issues in a couple of frameworks I distribute. The frameworks make heavy use of CFTypeRef objects. I would love to hear from anybody at Apple who can confirm that this is the way Analyze is meant to work.
>
If you want to avoid ambiguity, just add a CF_RETURNS_RETAINED annotation attribute to your method.
-- Jean-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden