I previously experienced a massive memory leak in SwiftUI on macOS which now seems to be fixed. CLICK
But my app still becomes slower and memory footprint grows after some time of using it. I was able to created a new minimal but more extreme example to reproduce:
This is a full app for SwiftUI. Compile for macOS (I'm using Xcode 12.4 macOS 11.2.3)
Code Block import SwiftUI @main struct DemoApp: App { @State var strings = ["Hello 1", "Hello 2"] @State var bool = false let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect() @State var selected: Int? var body: some Scene { WindowGroup { List(strings.indices, id: \.self, selection: $selected) { stringIndex in Text(strings[stringIndex]) } .toolbar(content: { ForEach(1...100, id: \.self) { _ in Text("Hello World") } }) .onReceive(timer) { input in if bool == true { selected = 0 } else { selected = 1 } bool = !bool } } } }
Timer is optional but it will show the problem more quickly. It seems to be connected to toolbar content a lot.
Memory footprint quickly goes up, as well as CPU utilization & app slows down significantly just after a few seconds. Please help! What can I do? My app is pretty much not usable because of this bug.
Johannes