help-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alloc/dealloc etiquette


From: Michael Ash
Subject: Re: Alloc/dealloc etiquette
Date: Sat, 17 Feb 2007 19:00:57 -0600
User-agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE-p20 (i386))

In comp.lang.objective-c Sherm Pendley <spamtrap@dot-app.org> wrote:
> Yeah, I'm a little skeptical of Apple's setters doing a -copy by default
> also. It seems to run counter to the whole idea of shared ownership that
> retain/release was designed to support in the first place.

Ah, but the really clever bit is that if you know that your objects are 
immutable, the retain/release mechanism lets you implement copy as a 
simple retain. Due to this, you should always copy in setters if they take 
an NSString, NSArray, etc. If it's mutable then you shouldn't be holding a 
reference to the original object anyway (it could change out from under 
you at any time) and if it's immutable then you get a very fast "copy" 
that doesn't actually do anything.

-- 
Michael Ash
Rogue Amoeba Software


reply via email to

[Prev in Thread] Current Thread [Next in Thread]