SwiftUI memory leak when referencing property from closure inside Form/NavigationView and swapping views
问题 I have something like this: struct SomeView: View { @ObservedObject var viewModel: SomeViewModel var body: some View { NavigationView { // <- culprit Button(action: { self.viewModel.logOut() }) { Text("X").frame(width: 40, height: 40) } } } class SomeViewModel: ObservableObject { func logOut() { // changes global state, based on which the views are swapped, so `SomeView` is removed and replaced by a different one } } When the button is pressed, SomeView is closed and a different view is