Spot the bug
The screen is never freed after it closes. Tap the line that creates the cycle.
final class ProfileViewController: UIViewController {let model = ProfileModel()var titleText = ""override func viewDidLoad() {super.viewDidLoad()model.onUpdate = { name inself.titleText = name}}deinit { print("freed") }}
Hint 1 of 1
Who owns the closure stored in onUpdate?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 6
model.onUpdate = { name in - Answer: line 7
self.titleText = name
The controller owns model, and model.onUpdate stores a closure that captures self strongly (lines 6–7). Use model.onUpdate = { [weak self] name in self?.titleText = name }.