Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is garbage collection used in production quality Cocoa apps?

I'm mainly wondering about the affect that garbage collection would have on performance. Is the use of garbage collection frowned upon for release apps?

Another concern that I can think of is that using garbage collection could lead to sloppier programming.

Do you use garbage collection in your apps?

like image 583
calvinlough Avatar asked Jan 02 '10 20:01

calvinlough


2 Answers

Garbage Collection is used in many production quality applications. Xcode, Automator, System Preferences and several other system applications are GC'd, and you can expect that trend to continue over time.

As well, many developers have embraced GC and are using it exclusively in their applications. Intuit's new versions of Quicken and QuickBooks for the Mac are garbage collected, for example.

There are a number of advantages of GC, too. Off the top of my head and from personal experience:

  • it makes multithreading easier; a simple assign is an atomic declaration of ownership

  • it offloads a bunch of memory management to other cores; it is naturally concurrent and offloads a bunch computation from the main thread (or computation threads)

  • in many cases, allocation and deallocation can happen entirely within the context of a thread, thus eliminating any need for global synchronization or locking

  • the collector has gotten faster with each release of Mac OS X and that trend will continue (just as it has with the rest of the system). By offloading more of your app's computational load to the system provided frameworks, your app will gain more and more from optimizations to the underlying system.

  • because the collector has intimate knowledge of the object graph -- of the pointers between objects -- in memory, it makes analysis and debugging significantly easier. Instead of "where did this dangling pointer come from?", the question is now "Give me a list of reasons why this object is sticking around longer than I think it should?".

This isn't to say that there isn't work to do to make your application work optimally under GC. There certainly are such tasks!

like image 131
bbum Avatar answered Sep 23 '22 01:09

bbum


Garbage collection has been around since the 1960s and is used in many released applications. All .NET apps use garbage collection. Apple uses libauto in Xcode.

Garbage collection generally leads to better quality apps in Cocoa since the developer is freed from the memory management burden. There are tons of Cocoa apps that leak! (though it may not a significant amount of memory)

I tend to use gc since since I can turn around my apps faster and don't have to worry about messaging zombie objects!

like image 37
caleb Avatar answered Sep 25 '22 01:09

caleb