Post

Replies

Boosts

Views

Activity

Memory Leak & Slow Down in SwiftUI for MacOS
Hi there, I previously experienced a massive memory leak in SwiftUI on macOS which now seems to be fixed. CLICK - https://developer.apple.com/forums/thread/676860 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) 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
7
0
4.6k
Dec ’21
Memory Leak & Slow Down in SwiftUI for MacOS
Hi there, I previously experienced a massive memory leak in SwiftUI on macOS which now seems to be fixed. CLICK - https://developer.apple.com/forums/thread/676860 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) 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
Replies
7
Boosts
0
Views
4.6k
Activity
Dec ’21