Get ready to dive deep into the inner workings of the Objective-C language and runtime! Each post delves into a specific aspect of the language and explores the details of its implementation. I hope you’ll find this valuable to demystify the language, tackle tricky bugs, and optimize your code for performance.
Objective-C Internals: Class Architecture
Objective-C has an unique class architecture where classes are objects. Its elegant design enables dynamic method dispatch for all object types through the use of a compiler generated metaclass.
Objective-C Internals: Class Graph Implementation
A brief look at the Objective-C runtime source code, focusing on the definition of object and class types, highlighting how inheritance is implemented, special cases for the root class, and quirks related to metaclass lookup.
Objective-C Internals: The Many Uses of isa
The Objective-C runtime optimizes performance by packing additional information into an object’s
isapointer. This post compares the different packing mechanisms and discusses the various field values stored in the pointer value.
Objective-C Internals: Unrealized Classes (and Toll-Free Bridging)
Objective-C unrealized classes may refer to future classes or class stubs. Future classes (a private runtime feature) facilitate toll-free bridging with CoreFoundation. And, class stubs are emitted by the Swift compiler to support interoperability between the stable Swift ABI and Objective-C.
Objective-C Internals: Non-Fragile Instance Variables
Objective-C instance variables may impact ABI stability. In Objective-C 2, Apple introduced a "non-fragile" layout to preserve ABI stability across some types of changes to a class’s instance variables.
Objective-C Internals: Tagged Pointer Objects
Tagged pointer objects (a private runtime feature) optimize performance by storing an object’s data in its pointer value, eliminating the object’s heap allocation. This post looks at the implementation of
NSNumberto highlight the use of and implications of this optimization.
Objective-C Internals: Associated References
A comparison of Apple’s Associated References implementation and one I wrote for historical context, with additional notes about use with tagged pointer objects and what the
assignassociation policy actually does.
Objective-C Internals: Retain
Objective-C memory is managed through a reference counting scheme, which has evolved from a relatively simple API into a sophisticated, highly-optimized implementation while maintaining source and ABI compatibility.
Objective-C Internals: Release
Although release is "just" the logical inverse of retain, its implementation is much more complex, primarily due to the ARM synchronization model. This post explores the unique aspects of the release implementation (relative to retain), focusing on the memory ordering requirements on ARM.