Understanding reference count ownership
Christiaan Hofman
cmhofman at gmail.com
Thu May 8 09:09:31 PDT 2008
On 8 May 2008, at 5:50 PM, Sherm Pendley wrote:
> On Thu, May 8, 2008 at 11:16 AM, Christiaan Hofman
> <cmhofman at gmail.com> wrote:
>
> E.g. initWithObjects:copyItems:. I couldn't find it in the ownership
> management docs, nor in the description of the method itself.
>
> There's no special mention in the method docs, because none is
> needed - the general rules apply to this method as-is.
>
The sentence I linked to and mmalc quoted clearly says 'contains
"copy"', and this method name obviously contains the word "copy".
> In fact, that description might make you believe that the objects
> from the array are copied, and therefore should be released by you!
>
> If the array calls -copy on the items that you've added, then *it*
> is responsible for balancing that -copy, *not you* - just like
> always. You didn't send the -copy message, so you are not
> responsible for balancing it. The inside of another object is Las
> Vegas - what happens there, stays there. Trying to balance code
> other than your own is what gets a lot of newbies into deep confusion.
>
> sherm--
>
> --
> Cocoa programming in Perl: http://camelbones.sourceforge.net
Notice that I'm using the word "might"; what I'm saying here is that
the description is not as clear as it could be. But the main point is
what I said above, which would imply that the created array has an
extra implicit retain (which of course is not true). And the
documentation of this method does not explicitly say that's not the
case.
I think the docs should say 'begins with "alloc", "new", "copy", or
"mutableCopy". Or is there an exception to that?
Christiaan
More information about the MacOSX-dev
mailing list