Understanding reference count ownership

Christiaan Hofman cmhofman at gmail.com
Thu May 8 06:32:24 PDT 2008


On 8 May 2008, at 3:16 PM, Paul Sargent wrote:

> On Thu, May 8, 2008 at 12:34 AM, mmalc Crawford <mmalc- 
> lists at mmalc.com>
> wrote:
>
>>
>> On May 7, 2008, at 2:47 PM, Christiaan Hofman wrote:
>>
>> No. The rule is that only methods containing "create", "copy", and  
>> "alloc"
>>> in their name implicitly retain.
>>>
>>> No, this is wrong.
>
>
> I have to say, even with a link to the documentation, that statement  
> just
> makes me more confused. I'm not sure what it is you're objecting to.
>
> Is it that objects returned by those methods haven't been  
> [retain]'d, they
> just haven't been [autorelease]'d?

I know, because I know what gets me confused. It's not "create" but  
"new". The confusion is partly due to the OP (who listed it as the  
part he said he understands), and partly due to Carbon, as there the  
similar keywords are "Copy" and "Create".

IMHO, I think the "new" rule was a mistake, because it's confusing  
(given the Carbon rule), and moreover it is rather an exception than a  
rule (I've never used it, and I know only a single example in Cocoa,  
which is an utterly expendable).

Also note that the documentation <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html 
 > is not sacred, as it has exceptions (which are not mentioned in the  
ownership docs AFAICS).

Christiaan


Christiaan



More information about the MacOSX-dev mailing list