Re: Copy and release
Re: Copy and release
- Subject: Re: Copy and release
- From: Wade Tregaskis <email@hidden>
- Date: Fri, 22 Oct 2004 23:45:50 +1000
From the converse point of view, if you want a mutable object because
you know you'll change it, you mightn't want to limit your callers to
providing a mutable version of the object... ultimately it's easier to
call mutableCopy once in your target method than in some, most or even
all your callers. As with the immutable case just mentioned, if the
given object is already of the correct mutability you'll just end up
retaining it.
Oops, got a bit over-zealous with the optimisations. :) "mutableCopy"
should never return the same instance, in normal circumstances, since
you've specified you want a mutable *copy*, which must be a different
instance from the original in the case where you want to modify the new
instance, but not have that effect the old one.
The upside in terms of efficiency is that by convention all mutable
classes are subclasses of their immutable versions, so you can always
specify the mutable subclass as the required type and prevent anyone
passing in an immutable version, if you really do want a mutable
instance but don't want to copy it (just retain).
Wade Tregaskis (AIM, Yahoo & Skype: wadetregaskis, ICQ: 40056898, MSN &
email: email@hidden, Jabber:
email@hidden
-- Sed quis custodiet ipsos custodes?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden