Re: ARC Retain Cycles
Re: ARC Retain Cycles
- Subject: Re: ARC Retain Cycles
- From: Andy Lee <email@hidden>
- Date: Mon, 21 Apr 2014 10:34:45 -0400
On Apr 21, 2014, at 8:27 AM, Dave <email@hidden> wrote:
> Also, when I did this, I left the property attributes as “retain” and “assign”, I’m wondering if it would be better to change them to “strong” and “weak” ? Although, AFAIK this shouldn’t make a difference?
For object properties, "strong" is a synonym for "retain", but "assign" is different from "weak". Weak properties are automatically set to nil when the object they reference goes away. If you use "assign" for an object property, it will not be automatically nil'ed and you may end up with a garbage pointer.
"weak" is not supported in 10.6 or 10.7, I forget which. If you need to support an OS version that supports ARC but not "weak", you should use the qualifier "unsafe_unretained" rather than "assign". It behaves the same, but it expresses intention better, plus you can later do a global replace to use "weak" when you decide to drop support for that old OS. In this case it's up to you to nil out that object property at the appropriate time.
--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