Is garbage collection used in production quality Cocoa apps?

后端 未结 5 1652
有刺的猬
有刺的猬 2021-02-06 09:34

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

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 09:55

    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!

提交回复
热议问题