-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViewModel is not cleared on iOS 17.4 #80
Comments
Could you possibly provide a minimal reproducible sample? |
I tried to do that with your sample but it worked as expected. I will probably fix the issue when I can reproduce it 😅 All I know is it works fine on 17.2, not on 17.4 |
Hi again @rickclephas . I've found out very interesting results. Here is my reproducible sample: I've added some flags:
If any of these flags are different then it is, it works fine. Also, pressing Back button on navigation bar works fine too. You should press Dismiss button to see it not clearing. This looks like a very interesting iOS bug but I'm not sure. By the way, with these combinations, it also doesn't work on iOS 17.2 or below. I'm using NavigationStack on my production app. But I couldn't make it "not work" with NavigationStack on your sample app. |
Okay i've added one more flag and reproduced version issue with NavigationStack and NavigationView (doesn't matter for this sample) . I think this is a strong reference issue but it works on 17.2 and below. Also back button or dismiss button doesn't make any difference.
As you can see in the sample, ContentView doesn't even have the reference to the DeeplinkHandler but it still causes the problem. |
Thanks for the reproducer! .onAppear {
if setDeeplinkHandler {
selectedChat = deeplinkHandler.chatId
}
} This logic is run right before the chat screen is closed. Another strange thing I noticed is that a non-null Making sure the deeplink logic in the Not sure why the initial deeplink navigation isn't working though. |
Btw using a verify basic class TestObject: ObservableObject {
init() {
print("TestObject init")
}
deinit {
print("TestObject deinint")
}
}
struct ContentView: View {
@StateObject var testObject = TestObject()
} It seems something has changed in SwiftUI that for some reason keeps state objects in memory when the |
thanks for the comments @rickclephas . the first reproducer commit may need another issue. it also has very interesting findings. using scrollview, textinput or navigation view causes the same issue. did you have a chance to check it out? |
Hmm I can't seem to reproduce it with that one. |
are you sure these flags are set:
I've tested on the same iOS and Xcode versions but it doesn't log the please be sure to checkout commit 46f11e3 |
I was testing on iOS 17.0 before and everything was working fine.
I'm using @StateViewModel. If there's anything more I can provide please let me know.
Edit: My code works fine on 17.2 and doesn't work on 17.4. But I couldn't reproduce it on the sample app. Looks like it's a bug on my code. It might be related to koin but I'm not sure.
Do you have any idea @rickclephas
Edit: It's not related to koin either. I've copied your TimeTravelViewModel and inited it just like you did
Even if the ChatScreen is deallocated, timeViewModel is not deallocated and not cleared.
The text was updated successfully, but these errors were encountered: