Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy and release



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Copy and release (From: Nicko van Someren <email@hidden>)
 >Re: Copy and release (From: Evan Schoenberg <email@hidden>)
 >Re: Copy and release (From: Nicko van Someren <email@hidden>)
 >Re: Copy and release (From: Paul Sargent <email@hidden>)
 >Re: Copy and release (From: Wade Tregaskis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.