> On Sep 26, 2019, at 5:43 PM, James Walker via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> On 9/26/19 4:20 PM, Gabriel Zachmann via Cocoa-dev wrote:
>>> The issue in the below code to my eye is that you allocate a path with 
>>> CGPathCreateWithRect (+1) but then don't release it.
>>> 
>>> In that case, I am wondering:
>>> doesn't ownership pass to the textlayer ?
>>> If yes, shouldn't textlayer release the path when it gets destroyed by the 
>>> ARC?
>>> 
>>> CALayer will indeed release shadowPath when it’s deallocated. However, 
>>> CALayer.setShadowPath doesn’t expect to be passed a +1 reference, so it 
>>> will retain/copy its argument, and it’s that retain which will be balanced 
>>> by the release during object destruction. Functions and methods generally 
>>> do not expect to be passed +1 objects.
>> So, if I understand you correctly, I should do this:
>>     textlayer.shadowPath = CGPathCreateWithRect( textlayer.bounds, NULL );
>>    CFRelease( textlayer.shadowPath )
>> ?
>> Is that correct?
> 
> That's not completely clear.  The documentation on shadowPath says "The value 
> of this property is retained using the Core Foundation retain/release 
> semantics".  However, a comment in CALayer.h says "Upon assignment the path 
> is copied."  If that's true, you'd be releasing the copy, not the original.  
> It would be safer to say:
> 
> CGPathRef thePath = CGPathCreateWithRect( textlayer.bounds, NULL );
> textlayer.shadowPath = thePath;
> CFRelease( thePath );
        If the path returned by CGPathCreateWithRect is immutable, which I 
think it is, then the copy made by shadowPath would likely be just a retain.  
However, I agree that assigning it to a variable is the better, less fragile, 
and more readable method.

—Rob



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to