April 2026
Intermediate
683 pages
25h 29m
English
To wrap up the topic of classes in Swift, we’ll address memory management now. This topic revolves around the lifecycle of classes—that is, how they live and die. In this section, you will learn how Automatic Reference Counting (ARC) works and how different types of references affect this lifecycle.
Because classes are reference types, multiple variables can point to the same object. If there are no more variables pointing to an object, then it can be safely removed from memory. Swift uses ARC to govern this mechanism.
Basically, Swift keeps count of the number of variables pointing to an object in memory. As soon as this count drops to zero, the object becomes obsolete and is destroyed, triggering its deinit.
Read now
Unlock full access