Michael Long
1 min readSep 5, 2019

--

The sink closure captures d2, a locally scoped variable, but has no reference to any variable or method on self, hence self is not captured.

class CombineTest {
let d1 = Deinit(1)
let subject = CurrentValueSubject<Int, Never>(0)
var cancellable: Cancellable?
func subscribe() {
let d2 = Deinit(2)
cancellable = subject
.sink { value in
print("\(value) \(d2.n)")
}
}
...
}

This is further reinforced by the fact that d1 is shown to release and deinit when CombineTest is released, which it would not do if there was a retain cycle on CombineTest.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)