Re: [[myObj retain] autorelease]
Re: [[myObj retain] autorelease]
- Subject: Re: [[myObj retain] autorelease]
- From: Ben Kazez <email@hidden>
- Date: Tue, 12 Jul 2005 20:52:20 -0400
On Jul 12, 2005, at 3:47 PM, Charilaos Skiadas wrote:
On Jul 12, 2005, at 2:32 PM, Ben Kazez wrote:
Sorry to ask a question about a topic that appears so frequently,
but here I go: I haven't been able to find anything that explains
when to use
return [[myObj retain] autorelease];
instead of just
return [myObj autorelease];
For example, Apple's default accessor methods do this. Is the
reasoning something to do with thread-safeness perhaps?
Those forms do not refer to the same thing. What you should be
comparing is:
return myObj;
versus
return [[myobj retain] autorelease];
Oops, you're right of course.
There were long discussions at some point as to which of the two is
the proper form for a getter, so you can find lots of discussions
in the archives. There is a long thread worth reading here:
http://cocoa.mamasam.com/COCOADEV/2002/08/1/41613.php
Thanks for the link; it has some very useful resources. I think
that's the longest Cocoa-dev thread I've ever seen!
The second form you refer to above is simply used when the method
has created myObj, and needs to release it but at the same time
return it, and make sure it does not get deallocated before whoever
called the method has the time to handle it. This is ASAICT the
typical use of an autorelease.
This much I understood (though evidently not enough to type it
correctly above).
Thanks for the help!
Ben
--
Ben Kazez
http://www.benkazez.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden