Linked by Thom Holwerda on Tue 27th Sep 2005 17:18 UTC, submitted by Eugenia
Thread beginning with comment 37109
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
RE: Objective-C gives you a choice
by japail on Wed 28th Sep 2005 00:35
in reply to "Objective-C gives you a choice"
RE: Objective-C gives you a choice
by on Wed 28th Sep 2005 07:49
in reply to "Objective-C gives you a choice"
I think the point of "return [[anObj retain] autorelease]" is simply to be able to create a non-copy/alloc function. Your caller expects the return value to be autoreleased.
For instance, if you fetch something out of an NSArray, you have to retain it (otherwise it could go away), but you also have to autorelease it because your function isn't called copy*** or alloc***.
Nothing more and nothing less.






Member since:
> ...why can't you have the choice to use auto-garbage collection or manual mem management?
With Objective-C, you _do_ have a choice, as there's nothing that prevents you from hooking up a "real" garbage collector to Objective-C. In fact, I remember reading a rumor that Apple is working on that. Certainly, they seem to be somewhat headed in that direction, anyway, given that they now recommend using "return [[anObj retain] autorelease];" in accessor methods instead of simply "return anObj;", since they surely realize how easy it is to screw up with manual memory management.