Routing WhenNavigatedTo: Memory leak bug or I am doing it wrong? #3481
Unanswered
HispidaBytes
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone 😃
I'm having an issue with the routing feature of ReactiveUI and I don't understand if I have found a bug or if I'm doing something wrong.
I wanted to test the the IRoutableViewModel WhenNavigatedTo functionality so I took this WPF Routing sample and added a call to that method inside the constructor of the SecondViewModel, like so:
It seems that a call to this method actually introduces a memory leak: The instance of the SecondViewModel never gets garbage collected when it's corresponding View goes out of focus (As it does when the "WhenNavigatedTo" method is not introduced).
The screen below comes from the Visual Studio 2022 memory profiler showing that an instance of SecondViewModel is still present even when I navigate away from it.
Now the problem does go away if I introduce the WhenActivated in the SecondViewModel to dispose the the IDisposable returned by the WhenNavigatedTo:
Is this how WhenNavigatedTo is actually meant to be used? By disposing the IDisposable that it returns?
Thank you in advance for any answer
Beta Was this translation helpful? Give feedback.
All reactions