Table Of Contents

iGC Overview

iGC is a garbage collection runtime designed for Apple’s iOS platform to collect unused objects, including retain cycles leaked in Automatic Reference Counting (ARC) and manual retain-release (MRR) code.

The core of iGC is based on HnxGC, which is an innovative cross-platform GC implementation. iGC inherits features from it, like accurate, pause-less, multiple inheritance, reclamation control, ..., and provides some iOS specific features, like Objective-C supports, collect cycles of block, array, ...

Accurate, pause-less and cross-platform

Previously, an accurate GC usually requires compiler helps to identify all references to objects, especially for variables on stack and CPU registers. This becomes rather complicated as compilers keep evolving to apply more and more advanced and intricate optimizations.

HnxGC perform accurate GC without information about variables on stack and CPU registers. It is easy to port HnxGC to a platform where there is no compiler helps available, such as iOS.

Further, this makes a fully concurrent GC possible, because there is no need to suspend a thread for a snapshot of references on stack and CPU registers. That is why HnxGC is pause-less as it never invokes suspend-thread system calls.

Immediate reclamation

HnxGC reclaims unused acyclic objects immediately as it maintains per-object reference counts internally. HnxGC also uses these counts to help garbage collection and reclaims objects in a non-nested way. ...

For cyclic objects, if you cannot wait for the completion of garbage collection, you can use Direct Kill to reclaim a “live” object and descendants immediately.

Multiple inheritance

Many GC implementations, like Java, do not allow multiple inheritance or embedding objects (C/C++ style composition). A few others use interior pointers to do that. However, the GC interior pointer is too slow for reference counting, which needs fast conversion from an interior address to the beginning of the object for frequently updating counts in applications threads (rather than in the collector doing GC traversal). Some people <think it is impossible to implement reference counting for a C/C++ style base and embedded objects. ...

HnxGC uses a new way of interior pointer for reference counting to support multiple inheritance, embedding objects, array of objects, etc.

This also makes Linear Pool mechanism possible to boost memory allocation performance significantly. (details)

Reclamation control

You are empowered to control the reclamation of cyclic objects, such as enforcing the order in which objects are reclaimed, resurrection before reclamation, destruct objects in main thread, etc. And there is no more finalizer or the like, just C++ destructor or Objective-C [dealloc] method.

Objective-C support

iGC provides patches to Xcode compilers, including GCC-4.2, LLVM-GCC-4.2 and Clang. So that you can write GC enabled Objective-C code without using C++ smart pointers or any HnxGC/iGC header files. It also provides a mode ARCGC_C that is source code level compatible to Apple’s ARC.

By linking against iGC, some types of cycles in old MRR and ARC code are collected. Good for cycles in binaries (no souce code available) of 3rd party libraries and Apple frameworks.

Other features

iGC can collect retain cycles of:

You can use smart pointers in Objective-C++ to avoid applying patches to your compilers, i.e. you can build a GC apps using any standard Objective-C++ compiler.

A GC enabled C++ class has the same layout and size as before. A HnxGC smart pointer is a single pointer, of the same size of "void*".

Reference counting is non-intrusive, and works on non-GC classes and primitive types also. It can even work on objects returned from non-GC code, like a FILE* returned from fopen function.

You can use Linear Pool to quickly allocate an object just in a few machine instructions.

Summary

iGC provides an accurate, fully concurrent and deterministic garbage collection for Objective-C/C++ iOS apps. It reclaims acyclic objects immediately the same as Apple’s reference counting (MRR and ARC), and collects cyclic garbage with reclamation control and performance boosted.