Does @State keep hidden copies of it's previous values somewhere?
I have a button that starts an async process. The button handler subscribes to a Combine publisher and saves the AnyCancellable in a @State var. Later, a cancel button sets the state var to nil.
When I set that to nil again, the subscription is not deallocated. If I make the simple change of moving mySubscription to a global var, or a property of an observed object, then it works as expected - the subscription is cancelled and deallocated.
(This is SwiftUI 2019, Xcode 11, not the new beta stuff.)
I have a button that starts an async process. The button handler subscribes to a Combine publisher and saves the AnyCancellable in a @State var. Later, a cancel button sets the state var to nil.
Code Block @State private var mySubscription: AnyCancellable? = nil
When I set that to nil again, the subscription is not deallocated. If I make the simple change of moving mySubscription to a global var, or a property of an observed object, then it works as expected - the subscription is cancelled and deallocated.
(This is SwiftUI 2019, Xcode 11, not the new beta stuff.)