TLDR Dev · MISCELLANEOUS
BITS & SIDE TABLES: HOW REFERENCE COUNTING WORKS IN SWIFT
Summary from the TLDR Dev newsletter
This is a deep dive into Swift's reference counting mechanism, explaining how strong, weak, and unowned references are implemented at the bit level within the Swift Runtime. It explains how strong references use inline bit counting and may use a side table when counts overflow or weak references exist. Weak references are slower due to indirection and potential cache misses from accessing a side table, while unowned references offer better performance but can lead to crashes if accessed after deallocation, keeping zombie memory alive.