Breaking Retain Cycles in Blocks
Diagnose and fix the most common ARC memory leak in legacy apps: retain cycles caused by blocks capturing self, using weak and strong references.
What is a Retain Cycle?
A retain cycle happens when two objects strongly reference each other. Neither's count can reach zero, so neither is ever freed — a memory leak ARC cannot break for you.
Blocks Capture Strongly
An Objective-C block captures the variables it uses, including self — and it captures them strongly by default. This is the number one source of cycles.
All lessons in this course
- Manual Retain-Release (MRR) Basics
- Automatic Reference Counting (ARC)
- Weak vs. Strong References
- Breaking Retain Cycles in Blocks