Skip to content
Commitwise
Menu

Automatic Reference Counting

Also called: ARC

Swift's memory management: each object counts how many strong references point to it and is freed at zero.

Definition

Automatic Reference Counting (ARC) adds and removes reference counts at compile time. When the last strong reference to an object goes away, it is freed immediately, which makes memory use predictable. The catch is retain cycles: two objects that strongly reference each other never reach zero, so you break the cycle with weak or unowned.

In practice

A view model holds a closure that captures self strongly, and the closure is stored on the view model. Neither is ever freed until you write [weak self] in the closure.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.