Purer Garbage

May 24th, 2006

As long time readers (and by long time I mean “more than a week”) will know, garbage collection has recently been on my mind – namely the proof that Apple will include Objective-C garbage collection in Mac OS X 10.5 codenamed “Leopard”, and set to be unveiled at this year’s Worldwide Developer Conference in August.

Or is it?

Xcode 2.3 just came out, and with it a newer revision of Apple’s version of GCC 4.0.1 (the original revision of 4.0.1 was included in Xcode 2.2). Most intriguingly, the man gcc output has changed when it comes to the infamous -fobjc-gc option! Here’s the new text:

       Enable garbage collection (GC) for Objective-C objects.  The
       resulting binary requires additional runtime support which is not
       present in any released version of Mac OS X.

       When the -fobjc-gc switch is specified, the compiler will replace
       assignments to instance variables (ivars) and to certain kinds of
       pointers to Objective-C object instances with calls to interceptor
       functions provided by the runtime garbage collector.  Two type
       qualifiers, "__strong" and "__weak", also become available.  The
       "__strong" qualifier may be used to indicate that assignments to
       variables of this type should generate a GC interceptor call, e.g.:

                 __strong void *p;  // assignments to 'p' will have interceptor calls
                 int *q;            // assignments to 'q' ordinarly will not
                 (__strong int *)q = 0;   // this assignment will call an interceptor

       Conversely, the "__weak" type qualifier may be used to suppress
       interceptor call generation:

                 __weak id q;      // assignments to 'q' will not have interceptor calls
                 id p;             // assignments to 'p' will have interceptor calls
                 (__weak id)p = 0;   // suppress interceptor call for this assignment

Still there? Good.

First of all, this version doesn’t mention OS X 10.5 in the least, whereas the previous version did very blatantly. What this means is that the feature is no longer guaranteed to be in for 10.5. My guess is that it will be in, but due to the change of operation (which I’ll come to in a second), Apple didn’t want to signal it too strongly.

Second, this method is definitely different than what we had before.

The Xcode 2.2 GCC (which is what I’m calling it, since both Xcode 2.3 and 2.2 GCC have the same version number – 4.0.1) had something else in mind entirely. It spoke only of a weak reference type (and not a strong reference type), and the Foundation Kit documentation in Xcode itself also noted the infamous finalize instance method on NSObject (the root object in Apple’s frameworks) which was designed especially to give you a dealloc-like hook for closing file handles and performing major cleanup. Xcode 2.3 GCC speaks of strong references as well, and the new Foundation Kit documentation in Xcode never mentions the finalize instance method at all.

Are we in for a brand new garbage collector before we even saw the first?

(Postscript: leeg notes in the comments that it could be a new way of describing the “old” GC with some amendments, which is true, and which is why I ended the post with a question. I truly don’t know a whole lot about the insides of garbage collectors, and I’m hoping for more input.)