On macOS, app's Settings model is not deallocated even after closing Settings window

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

  1. Run the project
  2. Open app's 'Settings
  3. Look at the console logs
  4. When model is created SettingsModel - init gets printed
  5. When Settings window is closed SettingsModel - deinit is 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()
        }
    }
}
On macOS, app's Settings model is not deallocated even after closing Settings window
 
 
Q