Advanced Swift: Memory Management
Memory management works like magic most of the time - until it doesn't. Find out what you need to watch out for in this course. By Ray Fix.
Learning path
This is part of the Advanced Swift learning path. View path.
Who is this for?
This course is for developers interested in getting a deeper understanding of the Swift language. It expects you to be comfortable with the basic syntax of Swift and to have perhaps written an app or two. You should be familiar with basic types in the Swift standard library.
Covered concepts
This course focuses on:
- Memory
- weak
- Closure captures
- unowned
- Function types
Automatic memory management in Swift is very low overhead and efficient but requires your cooperation for it to work right.
In this video we will look at how resource problems can occur, and how we can fix them using weak.
The unowned keyword hints the compiler that an object should not participate in reference counting. Sometimes it is the best solution.
In this video we've got a memory management challenge for you! This time, try adding weak to fix the leak.
Functions are reference types and can lead to reference cycles. Learn to break the cycle by controlling how references are copied into a closure's environment.
Swift has an elegant mechanism to let you prevent reference cycles from happening: the capture list.
Use closure captures to prevent leaks. In this video, let's do the strong-weak dance and other jigs.
In this challenge you will find yet another example of leaky code. Fix it with your new set of tools.
Knowing relationships between the objects in your system is the key to creating a leak free system.