Swift Robustness & AsyncLesson 39Free preview
Swift Memory
This lesson is part of Swift · All levels
Summary
This lesson is about Memory Management in Swift which is managed by Automatic Reference Counting (ARC). Developers will study the lifecycle of heap memory allocation, the dangers of Strong Reference Cycles (Memory Leaks) that occur when two objects hold strong references to each other, and the solutions using 'weak' and 'unowned' references.
Key points
- ARC automatically releases the class object memory when the reference count count is zero.
- The strong reference cycle occurs when two objects hold strong references to each other so that they are never released.
- 'Weak' references are always Optional and automatically zero when the designated object is destroyed
- The 'unowned' reference assumes that the target object is always present during the lifetime of the object's owner.
- Capture list on closure (e.g.: '[weak self]') is used to prevent retain cycle
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.