Detecting memory leaks using Unit Tests in Swift

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.

--

--

Jesús Alfredo Hernández Alarcón

Software Engineer with experience in mobile development using mainly agile methodologies. Experience with all Apple ecosystem.