Post

Replies

Boosts

Views

Activity

Reply to Memory Leak & Slow Down in SwiftUI for MacOS
Dear Apple, please fix this problem. With the simple app above the memory footprint quickly grows to gigabytes and when profiling with the Leak Detector, I see a huger number of leaks in SwiftUI internals. I spent quite some time and resources to build my app where this bug manifests and it prevents me from releasing it. How can such a big problem not be addressed? This is a very minimal and simple app and it still has this huge issue. Even though this is most noticeable with the Toolbar it manifests itself in other areas. In my app, the amount of leakage is drastically reduced when I remove the toolbar, but it still continues to leak when changing the State. Johannes
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Massive Memory Leak in SwiftUI for macOS
Thanks @rnikander, you're right, the upgrade helped fixing it. Seems like this minimal example was fixed. I still have a problem with my big app, though. Now, seems to be correlated to the toolbar component. I created a new thread with a new minimal example for this ( https://developer.apple.com/forums/thread/677969 ) Can you check if this is is causing problems on your end? Johannes
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Memory Leak & Slow Down in SwiftUI for MacOS
Note: If I change the app to this, there's no more leak because now the toolbar doesn't get invalidated and recreated. Swift import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { TestView() .toolbar(content: { ForEach(1...100, id: \.self) { _ in Text("Hello World") } }) } } } struct TestView: View { @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 View { List(strings.indices, id: \.self, selection: $selected) { stringIndex in Text(strings[stringIndex]) } .onReceive(timer) { input in if bool == true { selected = 0 } else { selected = 1 } bool = !bool } } } This is not possible for my original app though, because I need to dynamically switch the toolbar depending on context. This still seems like a pretty significant bug. How can I work around this?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21