I thought we all knew that Objective-C Garbage Collection was CONFIRMED!!!1 for Mac OS X 10.5 (”Leopard”). Color me wrong, I guess.
As for my personal opinion? I’m thrilled. The retain/release/autorelease trio is spectacularly easy to learn, but there are ‘magic conventions’ and ambiguities that make it so much harder. Magic conventions? How about this one: every class method or instance method whose name begins with its own class and which returns a potentially different instance of its own class (or a subclass thereof) always returns an autoreleased method.
Okay. Sure. Let’s take NSString as an example. -stringByAppendingString: returns an autoreleased string. +stringWithString: returns an autoreleased string. But how about -lowercaseString? It returns a string mutated from itself. But is it autoreleased?
Normally, this sort of thing is widely documented, but fairly regularly I run into ambiguities – or at least underdefining documentation – with Apple’s and especially third-party frameworks. With GC, all of that goes away. As experiments with Bindings and Core Data have proven, I’m willing to take a performance hit and a degree of control loss in order to streamline my coding and write less code. But it’s not just about that.
Scott Stevenson sums it up in an un-permalinkable comment on the same page where I brought up what I thought we all knew: “The point though, is really to simplify debugging for the developer and reduce crashes for the user. [..] the higher-level abstractions always seem to win out in the long run. It happened with Quartz, Cocoa Bindings and even as far back as C versus assembly. So while you may not use it right away, you almost certainly will eventually.”
Like Scott says, it’s not really about saving a handful of lines of code. Unless your app lives and dies with extreme performance (in which case you can turn garbage collection off – the confirmation came from a compiler switch, after all) you’re going to be just fine, and you’re going to rid yourself of a whole genre of problems. That “Leopard” can tentatively be pencilled in for Christmas can’t look like a coincidence for the Cocoa programmers of the world.
No comments yet.
Leave a comment
Your e-mail address is never shown. If you type a line break in the comment, it will show up as a line break (naturally). The following HTML is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>