Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftweak vs unowned mechanicsSingle-choice MCQ

An object has its last strong reference dropped to zero while a separate `unowned(safe)` reference to it still exists. What does the runtime do, and when can a trap occur?

final class Node { let id: Int init(_ id: Int) { self.id = id } deinit { print("deinit \(id)") } } func test() { var owner: Node? = Node(1) unowned let u = owner! owner = nil // strong -> 0 print("after owner=nil") _ = u // read here }