Re: ARC Retain Cycles
Re: ARC Retain Cycles
- Subject: Re: ARC Retain Cycles
- From: Andy Lee <email@hidden>
- Date: Mon, 21 Apr 2014 19:03:20 -0400
On Apr 21, 2014, at 5:18 PM, Kevin Meaney <email@hidden> wrote:
> On 21 Apr 2014, at 21:09, Andy Lee <email@hidden> wrote:
>>
>> The solution is to use a weak reference for one of the properties in the cycle. In general, if one object conceptually "owns" the other, then the "owning" object uses a weak reference and the "owned" object uses a strong one. For example, a parent has weak references to its children, and the children have strong references back to the parent. Similarly, a delegating object has a weak reference to its delegate, which typically (though not necessarily) has a strong reference back to the delegator.
>
> Unless I'm being confused here by your wording. Your recommendation in relation to the parent child relationship is completely turned around from what Apple suggests:
>
> https://developer.apple.com/library/ios/releasenotes/objectivec/rn-transitioningtoarc/introduction/introduction.html
> See section: Use Lifetime Qualifiers to Avoid Strong Reference Cycles
>
> If you are recommending an alternative to what Apple suggests I'd be quite interested into hearing the reasons. Do you implement an array of weak references to a list of children?
No, you got it right and I got it backwards. The "owning" reference is the strong one -- so, for example, a regular array of children does the right thing. My apologies.
--Andy
_______________________________________________
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