Memory Leak & Slowdown with SwiftUI on macOS

Viewed 230

I'm experiencing a dramatic increase in Memory footprint and slowdown of my macOS SwiftUI app. I was able to create a minimal example to reproduce. To reproduce go Xcode -> File -> New -> Project -> macOS -> App -> Life Cycle: SwiftUI App and paste&replace this into *App.swift

import SwiftUI
@main
struct DemoApp: App {
    let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect()
    @State var number = 0.0
    
    var body: some Scene {
        WindowGroup {
            List {}
            .toolbar(content: {
                ForEach(1..<100) { _ in
                    Text(String(format: "Time elapsed: %.1f ", number))
                        .font(.system(.body, design: .monospaced))
                }
            })
            .onReceive(timer) { input in
                number += 0.1
            }
        }
    }
}

I profiled the app and it has as massive number of leaks and memory footprint grows quickly: XCode Profiler

This bug is preventing me from launching my app. What can I do?

0 Answers
Related