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: Robert Vojta <email@hidden>
- Date: Wed, 29 May 2013 09:01:01 +0200
On Wednesday, 29. May 2013 at 8:37, Diederik Meijer | Ten Horses wrote:
> May I add two questions to this enlightening thread?
>
> 1. With ARC, do we still have to worry about string1 leaking in the following scenario?
>
> @property (nonatomic, copy) NSString *string1;
> …..
No, ARC perfectly manages this - no leaks in this case.
self.string1 = @"Hello";
self.string1 = @"Hello hello"; <- @"Hello" deallocated unless it's strongly referenced elsewhere
self.string1 = @"Hello hello hello"; <- @"Hello hello" deallocated unless it's strongly referenced elsewhere
> 2. How do the strong, copy and weak keywords in the property declaration affect this?
>
>
Here's nice tutorial from Ray http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1 You can learn something here.
Real life example …
strong - you're walking your dog on the lead, someone call your dog and he can't run
copy - like strong, but your dog is cloned and you're walking your new clone on the lead
weak - you're walking your dog off the lead, someone call your dog, he can run and you're without your dog
… if your property is weak and you do assign @"Hello" object to it, the object disappears and your property will be nil. That's because there's no strong reference to your @"Hello" object.
;-)
_______________________________________________
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