Re: Trying to understand -- please help...
Re: Trying to understand -- please help...
- Subject: Re: Trying to understand -- please help...
- From: glenn andreas <email@hidden>
- Date: Thu, 22 May 2008 16:42:22 -0500
On May 22, 2008, at 4:13 PM, Johnny Lundy wrote:
My point in using that class reference was simply to show how
someone could follow the "manual" and still have his code not work.
Actually, the "introductory documentation" never actually says that
the convenience constructors always return autoreleased objects --
it just says that they "in general" do (paraphrasing).
Even more reason, IMO, for the Class Reference to explicitly say
what the class does with the returned objects.
The way it is written, the objects are retained; so one should
conclude that they are not autoreleased.
If that is true, there is nothing wrong with the documentation.
But the focus shouldn't be on if the object returned is auto-released
or not, because it doesn't really matter what "producer" did, it
matters what the "consumer" wants to do.
For example:
[NSNumber numberWithInt: x];
May return an auto-released newly created object, or it may return a
cached singleton. For small numbers such as 0 and 1 (and probably a
bunch more) it'll be a cached singleton - the exact details are both
subject to change, and ultimately unimportant. You don't care where
that value comes from - if it is auto-released, or maybe a constant
that will live until your program exits, all you know is that if you
want to keep a reference to it for later, you'll need retain it.
So if the documentation for +[NSNumber numberWithInt:] said "returns
an auto-released object" it would be incorrect. And to say "in
general, it is auto-released" sounds like it wouldn't be any different
than what it says now (and thus no more helpful).
If you're focused on "is this auto-released or not" you're missing the
point. The memory management rules are all about "are you responsible
for it" (alloc, copy, etc...) and "do you want to keep it around" (and
then you need to decide if you want a reference to the object (retain)
or the value (copy/mutableCopy)). This is why it is important to
understand the memory management rules - once you understand them you
don't ever worry about those sorts of details...
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
m.o.t.e.s. | minute object twisted environment simulation
_______________________________________________
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