Closed pfandrade closed 5 months ago
@pfandrade This is a behavior of SwiftUI navigation: when a screen is presented and dismissed, often times the destination view and state are kept around in memory till the next presentation. You can take our vanilla SyncUps app that uses plain old observable models and add this to SyncUpFormModel
and you'll see the same behavior:
deinit {
print("DEINIT")
}
And the behavior is reproducible in much simpler apps, as well.
So I do not think you should depend on the lifetime of objects held in the view graph being tied to the lifetime of views on the screen, and instead you can depend on other, more predictable hooks.
Since this isn't a bug in TCA, and is just vanilla SwiftUI behavior, I'm going to convert this to a discussion.
Description
I'm finishing my first app with TCA and was trying to track down a memory leak. While doing so I found an unexpected behaviour in TCA:
If a sheet is presented and then dismissed, the associated feature state is not released after the dismiss. Only after the sheet is presented again is the state released. It seems the previous state is being held somewhere within TCA.
I've used the SyncUps example to confirm it's not something in my project. Here's a patch for the simple test I made:
Checklist
main
branch of this package.Expected behavior
I would expect that "DEINIT" is printed when the SyncUpForm is dismissed.
Actual behavior
"DEINIT" is only printed after the second time the sheet is presented.
Steps to reproduce
The Composable Architecture version information
5d73967c3ec8025626e07694c332aab77e6949a7
Destination operating system
iOS 17
Xcode version information
Version 15.3 (15E204a)
Swift Compiler version information