Re: copyWithZone - if anyone could explain this to me ?
Re: copyWithZone - if anyone could explain this to me ?
- Subject: Re: copyWithZone - if anyone could explain this to me ?
- From: Graham Cox <email@hidden>
- Date: Tue, 1 Dec 2009 12:34:02 +1100
On 01/12/2009, at 12:26 PM, Jeff Laing wrote:
>> In most cases, yes. However, copyWithZone: is special, the superclass'
>> implementation just blindly copies all of the raw bits in the source
>> object to the newly created one. If you were to use the normal
>> -setImage: call, that old value would be released one too many times.
>> Assigning to the instance variable in this case is the way to avoid
>> that.
>
> Why would you not just do:
>
> [cell->image retain];
>
> That makes it a lot clearer to me - since it was a bitwise copy, cell->image and image are identical values whereas the assignment looks like you are changing something.
You don't know that it was a bitwise copy - it depends on super's implementation. If you assume it was, you'll probably be wrong.
--Graham
_______________________________________________
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