Linked by Thom Holwerda on Tue 27th Sep 2005 17:18 UTC, submitted by Eugenia
Java Developers continue to debate the question of memory management solutions. Which is best? Although Objective-C's retain/release runs smoother and faster than Java's garbage collection, it places a much larger burden on the developer and introduces a much larger risk of memory leaks.
Thread beginning with comment 37109
To read all comments associated with this story, please click here.
Objective-C gives you a choice
by on Tue 27th Sep 2005 21:34 UTC

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.

japail Member since:
2005-06-30

The GNU runtime can be compiled with support for the Boehm conservative garbage collector, and POC works with it as well. There are of course limitations and caveats to using garbage collection in a C language.

Reply Parent Bookmark Score: 1

RE: Objective-C gives you a choice
by on Wed 28th Sep 2005 07:49 in reply to "Objective-C gives you a choice"
Member since:

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.

Reply Parent Bookmark Score: 0