-
Notifications
You must be signed in to change notification settings - Fork 49
ViewModel's Dispose is not being invoked unless page is refreshed #57
Comments
The disposal of a resource is determined by the lifetime of a resource. Usually you would use OwningComponentBase to circumvent this issue. However, having this as a base class has some implications that are not feasible when trying to use this library. This is indeed an issue but this cannot be resolved by just implementing If you have a good solution for this problem, I'll gladly take it. |
Well Implementing IDisposable in viewmodel(Service) with transient dependency would further cause memory leak as GC stores the reference for those objects with IDisposable type. thus I think the possible solution could be
Thus in this way one can do the clean up activity e.g Deregister events etc at the time of page close. If you think this could solve the problem, I would happy to raise PR |
That is the reason why |
How about having a Page Closed event in MvvmComponentBase which can be invoked when the page is Disposed thus one can do any cleanup activity on page close? |
@klemmchr like you suggested we could have one more class "MvvmOwningComponentBase" which inherit from OwningComponentBase just like the way you had created MvvmComponentBase for blazor framework's ComponentBase, we could have this new class as well. |
Yes, this is the only proper solution to this problem. I will address this together with #52 where the ground work for this is already set. This will also come with a breaking change so I will take this opportunity to upgrade it to .NET 6 while at it. |
@klemmchr You are right as per the documentation one should not call Dispose but if you look at the example provided by microsoft, the dispose method is called on each new request/refresh of the page but why would one refresh the page to call Dispose? and during my testing as well the Dispose method is called on Page Refresh.
"The debug console shows the following output after each refresh of the Index page:" ~Microsoft
In think there could be two way to solve this problem
What do you think?
Originally posted by @deveshbahuguna in #55 (comment)
The text was updated successfully, but these errors were encountered: