Re: NSMutableDictionary autorelease chrashes application
Re: NSMutableDictionary autorelease chrashes application
- Subject: Re: NSMutableDictionary autorelease chrashes application
- From: "Michael Ash" <email@hidden>
- Date: Fri, 18 Jul 2008 20:31:25 -0400
On Fri, Jul 18, 2008 at 7:48 PM, Andy Lee <email@hidden> wrote:
> On Jul 18, 2008, at 6:41 PM, Michael Ash wrote:
>>
>> On Fri, Jul 18, 2008 at 4:21 PM, Andy Lee <email@hidden> wrote:
>>>
>>> On Jul 18, 2008, at 3:49 PM, Michael Ash wrote:
>>>>
>>>> The better term already exists: "own". As in, "you own the return
>>>> value" or "you do not own the return value". This tells you everything
>>>> you need to know.
>>>
>>> Well, as I said I don't agree with the connotations of "own."
>>
>> I find that objection to be rather odd. Your objections are all corner
>> cases, or things where the English usage doesn't *quite* line up with
>> the programming usage.
>
> We'll just have to disagree on how odd the objections are.
>
> Corner case or not, we must understand that retains, wherever they occur,
> must be balanced with releases. Therefore we must understand that the same
> object can "own" another object multiple times -- it happens all the time.
> In fact, at the time you take ownership of something, you have no idea how
> many times you've owned it already. IMO this is not mere hair-splitting.
> It blows away the normal English concept of ownership, which is binary: you
> as an individual either own something or you don't.
I think it is hair splitting simply because it doesn't matter. You
only see this problem if you take a global view of the situation. But
the whole point of Cocoa memory management is to remove the
requirement to take such a global view. The concept of ownership can
be applied to the individual pointer variables, which makes this all
go away.
> This is why I never call the retain count a reference count, although it
> seems like the two terms have become interchangeable lately (I could swear
> that once upon a time the distinction mattered). Reference counts are about
> ownership; retain counts are about bookkeeping.
I've never heard such a distinction made before. I've seen "reference
count" used to describe bookkeeping all over the place, for example in
many primitive garbage collection systems.
> As for the "has-a" connotation, I suggest you ask any non-Cocoa developer
> what they think it means for one object to own another.
If they're coming from a garbage collected language I have no doubt
they'll be confused. If they're coming from a language which requires
manual memory management then I expect that they'll understand
immediately, because it's standard usage of the term. Using
"ownership" to indicate responsibility for freeing an object is
nothing unusual. The only unusual thing Cocoa does with it is allow
multiple owners.
See for example this random LinuxDevCenter article on C++ memory management:
http://www.linuxdevcenter.com/pub/a/linux/2003/06/19/cpp_mm-1.html
Same terminology, same basic concepts, just much greater difficulty
due to ownership being singular.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden