What is the primary memory management issue in this implementation of the delegate pattern?

iOS interview question for Intermediate practice.

Answer

A strong reference cycle is created between the DataProcessor and its delegate.

Explanation

A strong reference cycle (retain cycle) occurs because the ViewController instance has a strong reference to its dataProcessor property, and the DataProcessor instance has a strong reference back to its delegate (which is the ViewController). Because they both hold strong references to each other, neither can be deallocated, resulting in a memory leak. To fix this, the delegate property in DataProcessor must be declared as weak var.

Related Questions