Objective-C 2.0 Garbage Collection
Yesterday I was having a discussion about which Apple apps use the new garbage collection feature of Objective-C 2.0 (the fobjc-gc switch).
One of the reasons this topic comes up in Microsoft circles is the fact that so few Microsoft desktop applications use the CLR. As you may be aware, there is a performance cost associated with running code in the CLR and garbage collection often gets painted as the chief offender.
I had heard that several Apple apps in 10.5 used this feature, but I had never followed up to know for sure. Yesterday I decided to take a look. Since I am a complete hacker, I decided not to ping the Apple lists and just see if there was a way to figure this out myself.
Based on my digging around (nm is your friend), I believe the following apps (of the subset I looked at in 10.5) use GC:
- iChat
- Preview
- PhotoBooth
I looked at the iLife apps too, but none of them had the signs of GC. However, GC is a feature of 10.5 and iLife supports 10.4 — so that likely explains it.
I have to tell you and I have said this before at Microsoft, Apple did a very cool thing here. They had most apps on the same “unmanaged” memory allocator/scheme (ref count with autorelease) and then they shimmed in GC as an optional feature. Even more important (and far cooler in this world of a new framework every 10 minutes), is that Objective-C/NeXTStep/OpenStep/Cocoa has been around since the late 1980s and just getting better with age…
[Updated: The above list of apps is wrong. See http://www.douglaspurdy.com/2008/06/14/objective-c-20-garbage-collection-part-ii/.]
Right.
MS complain that the uptake of WPF is slow. I put this down to Microsoft not dogfooding the technology more than the tech itself.
Look at AJAX – that was very hard to get right before we had supporting toolkits. It was only when Google demonstrated it in their predictive text search box when it got the real interest of developers.
What happened to Microsoft Max?
Why doesn’t Windows Live Mail etc use WPF?
Why have Yahoo got a Vista IM client written in WPF and MS doesn’t.
Joe
12 Jun 08 at 23:28
[...] 2.0 Garbage Collection Posted in June 12th, 2008 by in Uncategorized Objective-C 2.0 Garbage Collection Yesterday I was having a discussion about which Apple apps use the new garbage collection feature [...]
» Objective-C 2.0 Garbage Collection A C One: What The World Is Saying About A C One
12 Jun 08 at 23:35
XCode also uses GC
Simon Fell
13 Jun 08 at 02:15
I’m not sure how you determined which applications use garbage collection on Leopard, but as best I can tell exactly none of the four applications you list do. However, as Simon Fell mentions Xcode *does* use garbage collection:
mrowe@daisy:~$ otool -oV /Applications/Mail.app/Contents/MacOS/Mail | tail -n3
Contents of (__OBJC,__image_info) section
version 0
flags 0×0 RR
mrowe@daisy:~$ otool -oV /Applications/iChat.app/Contents/MacOS/iChat | tail -n3
Contents of (__OBJC,__image_info) section
version 0
flags 0×0 RR
mrowe@daisy:~$ otool -oV /Applications/Preview.app/Contents/MacOS/Preview | tail -n3
Contents of (__OBJC,__image_info) section
version 0
flags 0×0 RR
mrowe@daisy:~$ otool -oV /Applications/Photo\ Booth.app/Contents/MacOS/Photo\ Booth | tail -n3
Contents of (__OBJC,__image_info) section
version 0
flags 0×0 RR
mrowe@daisy:~$ otool -oV /Developer/Applications/Xcode.app/Contents/MacOS/Xcode | tail -n3
Contents of (__OBJC,__image_info) section
version 0
flags 0×2 GC RR
mrowe@daisy:~$
The field of interest here is the “flags” field of the __image_info section of the __OBJC segment. If garbage collection is supported it will have the value 0×2 and will be shown as “GC RR” to represent that both garbage collection and retain/release are supported. If garbage collection is *required* then the field will have the value 0×4 and will be shown as “GC-only” indicating that only garbage collection is supported and that retain/release is not available. The field can also contain other values, but those two are the only values that are relevant to garbage collection.
Mark Rowe
14 Jun 08 at 07:22
[...] Posted in Apple It turns out I was wrong (it will not be the last time) about the four apps I pegged as possibly using GC in 10.5 here. [...]
Objective-C 2.0 Garbage Collection, Part II « Douglas Purdy
14 Jun 08 at 08:28
Hi there can I use some of the material here in this entry if I reference you with a link back to your site?
Benton Sisto
12 Jun 10 at 00:02