logoalt Hacker News

atombendertoday at 12:00 AM6 repliesview on HN

I've made a tiny SwiftUI app. It was really difficult to figure out the memory leaks. In fact, I have leaks that I still haven't been able to find. For some reason the heap is fine, but the app continues to allocate virtual memory.

I've thrown Claude and Gemini at the app to try to analyze the code, had them use vmmap and Instruments, asked them run all of the code in a loop to reproduce the leakage — and still it leaks, slowly, tens of megabytes per day.

I'm sure it's something simple starting me in the face. But the fact remains that Swift's sort-of-automatic-but-not-quite memory model still makes it much harder to reason about memory than Rust or even Go.


Replies

rTX5CMRXIfFGtoday at 3:07 AM

I agree, but I think that it's difficult to spot memory leaks in SwiftUI because it's such a high-level abstraction framework. When working with the Cocoa and Cocoa Touch libraries, it's so much easier to find.

And of course, Apple's UI frameworks != Swift the language itself.

groundzeros2015today at 2:36 AM

The memory management is almost broken. They decided not crashing was better than mashing memory.

teunispeterstoday at 1:14 AM

hunting dangling references in a reference counted system is like that.... that's all I can guess is going on here. Good hunting! I wonder if there's a resource debugger? So far when I have really had to look, xcode was suffiicent... but there's likely better out there for finding this kind of thing.

jabwdtoday at 4:02 AM

I'm sorry but what exactly are you doing? This is the first time I've ever heard any of this type of reasoning, and well, the fact that you're using AI makes me think you have no clue what you're actually talking about.

If its a reference cycle, instruments will find it. If it is a leak, instruments will find it. However, you seem to be worried about an implementation detail on how you get memory from your CPU which the mach kernel handles for you, and is something you don't quite grasp.

please don't reply with "I asked stupid generator", seriously, what is the actual issue you have?

cosmic_cheesetoday at 12:13 AM

Personally I avoid using SwiftUI except in bite size chunks like collection view cells. It’s great for that kind of use case but doesn’t scale up well.

I wasn’t of the mind that AppKit/UIKit really needed replacing in the first place, though…

show 1 reply
heavyset_gotoday at 12:28 AM

What's the issue if it allocates virtual memory?

show 1 reply