Replies: 1 comment
-
Hi @Lumisilk, in general it is best to only capture present(item: $model.child) { childModel in
ChildViewController(model: childModel)
} Since I don't think this is an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Consider
ViewModel
is a@Observable class
.If I capture the viewModel in the ViewController-making content closure of
.present
(or any method else) like this:After dismissing SheetViewController, the viewModel keeps alive. Even SheetViewController did actually been deinited.
I'm not sure this is a bug or expected behavior.
If I have to use ViewModel to create another UIViewController, how can I avoid this problem and get ViewModel be released?
Maybe something like this?
Another similar situation
If I use
observe
and capture ViewModel in the closure, the ViewModel will be retained after dismissing only when I access the property of ViewModel. This behavior is expected because the closure was "registered" on the ViewModel itself.But in the example code of the main topic, I didn't even access any property of ViewModel.
Checklist
main
branch of this package.Expected behavior
ViewModel should be released.
Actual behavior
ViewModel got retained.
Steps to reproduce
I've uploaded a tiny project to reproduce this problem.
https://github.com/Lumisilk/SwiftNavigationBugExample
SwiftUI Navigation version information
2.2.2
Destination operating system
iOS 17, 18
Xcode version information
Xcode 16.1
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions