Re: Questions regarding release
Re: Questions regarding release
- Subject: Re: Questions regarding release
- From: "Glenn L. Austin via Cocoa-dev" <email@hidden>
- Date: Thu, 26 Sep 2019 17:07:31 -0700
> On Sep 26, 2019, at 9:47 AM, Gabriel Zachmann <email@hidden> wrote:
>
>>
>> I don’t believe that’s entirely true. “make” methods return a +0 value.
>>
>> 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?
>
> Best regards, Gabriel
>
Setting the value will retain it for itself.
--
Glenn L. Austin, Computer Wizard and Race Car Driver <><
<http://www.austinsoft.com>
>
>> Mike.
>>
>>> On 26 Sep 2019, at 17:16, Glenn L. Austin via Cocoa-dev
>>> <email@hidden> wrote:
>>>
>>> The analyzer is great at what it does but it can't be omniscient about your
>>> code.
>>>
>>> When you start a method name with "make" or "new" or "create" it assumes
>>> that you're returning a +1 value.
>>>
>>> --
>>> Glenn L. Austin, Computer Wizard and Race Car Driver <><
>>> <http://www.austinsoft.com>
>>>
>>>> On Sep 26, 2019, at 6:05 AM, Gabriel Zachmann via Cocoa-dev
>>>> <email@hidden> wrote:
>>>>
>>>>
>>>>>
>>>>> The Xcode "analyze" step should check for errors of this kind. I have
>>>>> xcode set to analyze on every build, since it's usually not too slow.
>>>>
>>>> Thanks a lot for the hint!
>>>>
>>>> I tried it and it works pretty well.
>>>> I actually found 2 (small) leaks.
>>>>
>>>> There is one place in my code (different from my OP),
>>>> where I get a "leaked" warning from the Analyzer, but I am not sure why
>>>> that is.
>>>>
>>>> Here is what the function basically does:
>>>>
>>>> - (void) makeTextLayerRectangle: (CATextLayer*) textlayer fontsize:
>>>> (float) fontsize text: (NSString*) text
>>>> {
>>>> ...
>>>> textlayer.bounds = CGRectMake( 0.0, 0.0, string_rect.width,
>>>> string_rect.height );
>>>> textlayer.shadowPath = CGPathCreateWithRect( textlayer.bounds, NULL );
>>>> }
>>>>
>>>>
>>>> But I get the warning
>>>> "Object leaked: allocated object of type 'CGPathRef _Nonnull' is not
>>>> referenced later in this execution path and has a retain count of +1"
>>>>
>>>> Note that text layer is a call-by-reference var.
>>>>
>>>> Is that just a bug in the Analyzer? Am I missing something?
>>>>
>>>> Best regards, Gabriel
>>>>
>>>> _______________________________________________
>>>>
>>>> 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
>>>
>>> _______________________________________________
>>>
>>> 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
>>
>
Attachment:
signature.asc
Description: Message signed with OpenPGP
_______________________________________________
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