Detecting memory leaks using Unit Tests in Swift
4 min readFeb 26, 2021
Memory management is a topic that every time we write code, it needs to be handled. Fortunately Swift helps us with the Automatic Reference Counting (ARC). But human errors are still there and as we saw in the last entry one common mistake we commit is Retain Cycles.
A retain cycle is generated when an Object A retains another Object B and Object B retains Object A. Let’s see an example:
Suppose we have two objects Parent
and Child
, and create two references to it.