Problem
- On the macOS when Settings view is closed, the @State model is not deallocated
Feedback
- FB21393010
Environment
- macOS: 26.2 (25C56)
- Xcode: 26.2 (17C52)
Steps to reproduce
- Run the project
- Open app's 'Settings
- Look at the console logs
- When model is created
SettingsModel - initgets printed - When Settings window is closed
SettingsModel - deinitis not printed, meaning it is not deallocated
Code
SettingsModel
import SwiftUI
@Observable
class SettingsModel {
init() {
print("SettingsModel - init")
}
deinit {
print("SettingsModel - deinit")
}
}
SettingsView
import SwiftUI
struct SettingsView: View {
@State var model = SettingsModel()
var body: some View {
Text("Settings")
.font(.largeTitle)
.padding(200)
}
}
App
import SwiftUI
@main
struct SettingsBugApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
Settings {
SettingsView()
}
}
}