Member-only story

Practical Reference Cycles in Swift

Don’t let this stop you!

Steven Curtis
3 min readFeb 21, 2022
Photo by Hunter Haley on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.0, and Swift 5.3

https://youtu.be/7NYXD-sRopg

There are plenty of guides about reference cycles in Swift, and many of them will recommend you using [weak self] to get out of trouble.

Prerequisites:

Terminology:

Capture lists: The list of values that you want to remain unchanged at the time the closure is created

Capturing values: If you use external values inside your closure, Swift stores them alongside the closure. This way they persist even when the external part of the code no longer exists

Closure: A self-contained block of functionality that can be passed around

The project

Reference cycles are something that every iOS developer should be aware of, as they can cause memory leaks (which are memory allocations that are never released).

--

--

No responses yet