General topic questions
ARC and retain cycles
MediumMost asked
Free section · general topics & algorithms
Explain Automatic Reference Counting (ARC). When do retain cycles happen, and how do you break them with weak and unowned references?
Reveal model answer
ARC tracks strong references and frees objects at zero. Cycles usually appear in closures capturing self, or parent↔child object graphs. Use weak for optional back-references (delegates, closures that may outlive the object) and unowned when the reference is non-optional and guaranteed to outlive the capture. Always capture lists in escaping closures: `[weak self]`.