Re: What, exactly constitutes a mutable action on an instance?
Re: What, exactly constitutes a mutable action on an instance?
- Subject: Re: What, exactly constitutes a mutable action on an instance?
- From: Quincey Morris <email@hidden>
- Date: Wed, 29 May 2013 00:26:07 -0700
On May 28, 2013, at 23:37 , Diederik Meijer | Ten Horses <email@hidden> wrote:
> 1. With ARC, do we still have to worry about string1 leaking in the following scenario?
>
> @property (nonatomic, copy) NSString *string1;
> …..
> self.string1 = @"Hello";
> string1 = @"Hello hello";
> string1 = @"Hello hello hello";
No, you don't have to worry. When dealing with objects, ARC handles all retain/release correctly, regardless of whether the assignment is to the property or the ivar. That's kinda the point.
> 2. How do the strong, copy and weak keywords in the property declaration affect this?
ARC still does the right thing, whether you use the ivar or the setter.
The "ownership" keyword is multi-purpose (unfortunately, IMO):
1. It defines the ownership attribute of a synthesized ivar (or must match the ownership attribute of a manually declared ivar). For this, copy is the same as strong.
2. It defines the behavior of a synthesized setter. For this, copy makes a copy, everything else just does an assignment (with the appropriate memory management according to the ivar ownership attribute).
3. It declares the ownership attribute of the property itself, separately from the ivar. For this, strong and copy represent a strong property; weak represents a weak property; __unsafe_unretained represents no ownership. However, the property's ownership attribute has no actual effect on the compiler. Everything the compiler does via synthesis is covered under #1 and #2.
Note that #1 and #2 are in truth private implementation details of the class. #3 is the public API contract, and communicates to clients of the class whether the property takes ownership of the property value.
_______________________________________________
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