Spot the bug
PlayerScreen never prints 'screen freed'. Tap the line that causes the leak.
protocol PlayerDelegate: AnyObject {func didFinish()}final class Player {var delegate: PlayerDelegate?}final class PlayerScreen: PlayerDelegate {let player = Player()init() { player.delegate = self }func didFinish() {}deinit { print("screen freed") }}
Hint 1 of 1
Draw the arrows: who owns whom?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 5
var delegate: PlayerDelegate?
Line 5 makes the player hold its delegate strongly, while the screen owns the player. Make it weak var delegate: PlayerDelegate?.