Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Adopting Garbage Collection

Garbage collection provides trade-offs that you need to consider when choosing whether to adopt the technology.

Potentially, any application that uses a runloop may use garbage collection, however there are issues you should consider when deciding whether it is appropriate for your application. Garbage collection provides several advantages when compared with manually managed memory; there are also, though, some disadvantages. The benefits tend to be greater if the application is threaded and has a reasonably large working set; they tend to be less if the latency of memory recovery is important. Moreover, managed memory and garbage collected applications use a number of different idioms and patterns.

For information relating to garbage collection in the current release of Mac OS X, see Garbage Collection Release Notes.

Note: The process of migrating a large project that uses managed memory can be difficult and error-prone—some patterns that work correctly with manual memory management will be incorrect after translation. In general, it is recommended that you use garbage collection only in new projects. If you already have a well-architected, well-understood application that uses managed memory, there should be little reason to migrate to GC.

Contents:

Advantages and Disadvantages
Performance


Advantages and Disadvantages

Garbage collection offers some significant advantages over a managed memory environment:

Garbage collection does though have some disadvantages:

Performance

The performance characteristics of an application that uses garbage collection are different from those of an application that uses managed memory. In some areas, a garbage-collected application may have better performance, for example:

In other areas, however, performance may be worse:

When analyzing the performance of a garbage-collected application, you typically need to take a longer-term approach than with a managed memory application. When assessing its memory footprint, it may be appropriate to measure after the application has been running for several minutes since the memory footprint may be greater shortly after launch. The profiling tools you can use include heap, gdb flags, and the Instruments application.



< Previous PageNext Page > Hide TOC


Last updated: 2008-03-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice