NavigationPath retaining view models

I'm seeing NavigationPath retaining objects after they've been popped off the path.

It is showing up as:

SwiftUI.(ItemBox in $10b3430a8)<Project.ViewModel>
NavigationPath_ItemBoxBase
_TtCs12_SwiftObject

If I follow that path up it eventually ends with:

SwiftUIEnvironmentWrapper

Looks like that is being used/held/managed by something like:

<SwiftUI.(TypedElement in $10b356118)<SwiftUI.(EnvironmentPropertyKey in $10b35f1b0)<SwiftUI._NavigationAuthority_State.Key>> 0x600003078800> [128] +88

Basically I have a class view model that subscribes to hashable and gets pushed on the path. Navigation works correctly. I pop that object off the path, correctly animates back and I'm left at the root view.

Take a memory snapshot and that object is still alive, along with everything it's holding onto. If I inspect the navigation path it has a 0 count.

Any idea how I can free this object from its environment object prison?

Seems I have the same issue

Bump

Yeah, I have spent a long time looking into the same thing.

If you do not use the built in back button and use your own back button, where the back button will removeLast from the NavigationPath, this solves the issue.

Follow ItemBox back and it is the UIKit NavigationTitleBar retaining the object.

Can you fix this Apple? This breaks the architecture I wanted to use with managed lifecycles of sub-page view models.

NavigationPath retaining view models
 
 
Q