Re: static analyzers says I'm leaking, I _think_ I'm not
Re: static analyzers says I'm leaking, I _think_ I'm not
- Subject: Re: static analyzers says I'm leaking, I _think_ I'm not
- From: Ken Thomases <email@hidden>
- Date: Wed, 06 May 2015 16:54:35 -0500
On May 6, 2015, at 4:40 PM, Aaron Montgomery <email@hidden> wrote:
> If the property is set to "retain", then the line
>
> self.cycler = [[[….initWithGrid:self] autorelease]
>
> will cause the setter to retain the passed in object, so after this line, _cycler will have a (heuristic) retain count of 2 (an alloc and a retain).
>
> After this, when the autorelease pool is drained, reducing the (heuristic) retain count by 1: you've still got a hold of it in the property.
>
> Then in dealloc, you release the object in dealloc to reduce the (heuristic) retain count to 0.
Or, in other words, sending an object -autorelease is just like sending it a -release only the effect is delayed.
A combined alloc/init/autorelease balances itself. A strong (or "retain") property will be balanced if the setter is written properly (which a synthesized setter will be) and you release in -dealloc.
> To release the object, you can use
>
> [_cycler release];
>
> or
>
> self.cycler = nil;
Better to use the former in case the setter (in this class or a subclass) does extra work that wouldn't be appropriate during deallocation.
> or you may be able to not even bother if you won't create a cycle, I haven't done manual memory in a while, but I think retained properties are released at destruction automatically.
No, in manual retain-release, nothing is released automatically. In -dealloc, you have to explicitly release the objects you own.
Regards,
Ken
_______________________________________________
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