Re: NSMutableDictionary autorelease chrashes application
Re: NSMutableDictionary autorelease chrashes application
- Subject: Re: NSMutableDictionary autorelease chrashes application
- From: Andy Lee <email@hidden>
- Date: Fri, 18 Jul 2008 15:20:36 -0400
On Jul 18, 2008, at 2:27 PM, Shawn Erickson wrote:
On Fri, Jul 18, 2008 at 10:20 AM, Andy Lee <email@hidden> wrote:
Unless Apple defines another adjective for this purpose, it seems
to me that
"autoreleased" is a reasonable shorthand for "you must retain it if
you want
it to stick around, or you *may* have a dangling pointer."
Similarly,
"retained" is a reasonable shorthand for "you must balance the
method you
just called with a release, or you'll have a memory leak."
Autorelease has a specific meaning (not the one you imply above) and
as you note few APIs document it since it really is unimportant to
know. My point was it is an implementation detail.
Oh, yes, I definitely get that whether a returned object is
autoreleased (in the correct technical sense) is an implementation
detail. *My* point was that as a matter of language, there is no
official adjective for the kind of returned object we're talking
about. It may be lazy, it may be sloppy, it may be inaccurate, but I
understand why people use the word the way they do.
Apple attempts to consistently talk in terms of an object ownership.
Did you create an object or retain it, if so then you own it... if not
then you don't. If you own it then it will persist at least until you
release ownership. etc. The only issue I have with the term ownership
is that to most folks "owning" something implies a single owner but in
the case of objects you can have multiple owners at any given time. As
long as folks understand that then ownership works well to describe
this.
I actually feel more strongly about the term "ownership," and I'm glad
you expressed a bit of misgiving about it, because I've felt sort of
heretical about it, given how much the MemoryMgmt doc relies on the
concept. I would go so far as to say the word is misleading, because
its connotations don't match what is really going on:
* As you say, an object can have multiple owners, but I agree, that is
not necessarily so confusing.
* However, the same owner can own an object multiple times, and you
have to disown it as many times as you own it, which is not at all
like the plain English meaning of ownership.
* "Object ownership" to me connotes a "has-a" relationship, as in
having something as an ivar; but there are plenty of cases where we
alloc/init an object that is not an ivar.
I'll try not to beat this to death; I've just been wanting to say
something about the "ownership" concept for a while.
--Andy
_______________________________________________
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