[Top][All Lists]

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

Re: GSIMap

From: Richard Frith-Macdonald
Subject: Re: GSIMap
Date: Sat, 25 Jun 2011 15:32:37 +0100

On 25 Jun 2011, at 08:56, Helge Hess wrote:

> On Jun 10, 2011, at 6:14 AM, Richard Frith-Macdonald wrote:
>> is pretty much unique to you I think
> I was also assuming that -retain can return a different object. Otherwise it 
> should be void (aka AddRef()) ...

I'm all in favour of defensive programming like doing things like checking the 
result of -retain but ...

See the Apple documentation at

As you can see retain returns self, it does so as a convenience for use in 
nested expressions and it is specifically a no-op in gc environments (which 
means that the compiler/runtime is free to remove the call to -retain entirely 
if you are using gc). 

Short of saying something like 'this method really, *really*, REALLY never 
returns a different object from the receiver', I don't see how the 
documentation could be clearer, and I'm certain there is a lot of code written 
by a lot of people which depends on the documented behavior, so overriding 
-retain to do something else would be a fault/bug.

The clang compiler even complains that you are assigning a value to itsself if 
you write 'x = [x retain]' 

So if you write code which overrides -retain to return a different object, the 
code is broken and you deserve what you get ... the documentation says its 
wrong, the compiler says it's wrong, and in a gc environment the retain method 
probably won't even be called. 

Anyway, this is my last post on this topic ... I think it's been done to death.

reply via email to

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