reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
https://www.reactiveui.net
MIT License
8.1k stars 1.12k forks source link

[BUG] Xamarin Forms repeated TabNavigation causes app to slow and eventually lock #1983

Closed lackrin closed 5 years ago

lackrin commented 5 years ago

Describe the bug When implementing Xamarin Forms Tab Navigation, where each tab is a page with its own navigation, the app will quickly start to Slow down on navigations, where the first navigation will be instant, but the 5th will take seconds.

Steps To Reproduce Provide the steps to reproduce the behavior: setup a tab page with each tab having its own routedviewhost

            var homeDashboardView = Locator.CurrentMutable.GetService<DashboardViewModel>();
            homeDashboardView.Router.NavigateAndReset.Execute(homeDashboardView).Subscribe();
            Locator.CurrentMutable.RegisterConstant(homeDashboardView, typeof(IScreen));
            hostDashboardView = new RoutedViewHost { Router = homeDashboardView.Router, Title = "\uf0b1 Jobs" };

            var homeMapView = Locator.CurrentMutable.GetService<MapViewModel>();
            homeMapView.Router.Navigate.Execute(homeMapView).Subscribe();
            Locator.CurrentMutable.RegisterConstant(homeMapView, typeof(IScreen));
            hostMapView = new RoutedViewHost { Router = homeMapView.Router, Title = "\uf279 Map" };

            var homeDocumentsView = Locator.CurrentMutable.GetService<DocumentsViewModel>();
            homeDocumentsView.Router.Navigate.Execute(homeDocumentsView).Subscribe();
            Locator.CurrentMutable.RegisterConstant(homeDocumentsView, typeof(IScreen));
            hostDocumentsView = new RoutedViewHost { Router = homeDocumentsView.Router, Title = "\uf0c6 Document(s)", IsVisible = false };

            NavigationPage.SetHasNavigationBar(hostDashboardView.CurrentPage, false);
            NavigationPage.SetHasNavigationBar(hostMapView.CurrentPage, false);
            NavigationPage.SetHasNavigationBar(hostDocumentsView.CurrentPage, false);

            this.Children.Add(hostDashboardView);
            this.Children.Add(hostMapView);
            this.Children.Add(hostDocumentsView);

            Locator.CurrentMutable.RegisterConstant(homeDashboardView, typeof(IScreen));

Expected behavior you should navigate to the next page, but the tabs persist. This works, except for the fact that each navigation takes longer and longer, until the point where the app will no longer respond. Pages/VM are never GC'ed.

Environment(please complete the following information):

RLittlesII commented 5 years ago

@lackrin Thank you for reporting this issue. I see that you provided some sample code. Do you have capacity to provide a full sample? This helps verifying the fix when the issue is resolved.

I also noticed you explicitly stated that it is a Xamarin.UWP issue, are you seeing this in any other Xamarin targets?

lackrin commented 5 years ago

I can try to make a sample app to get the same results. I actually haven't tested with anything else because UWP is our primary platform

Do you have any examples of tab navigation where the tab remains the parent and only the tab content navigates?

On Mar 25, 2019 11:50 AM, Rodney Littles II notifications@github.com wrote:

@lackrinhttps://github.com/lackrin Thank you for reporting this issue. I see that you provided some sample code. Do you have capacity to provide a full sample? This helps verifying the fix when the issue is resolved.

I also noticed you explicitly stated that it is a Xamarin.UWP issue, are you seeing this in any other Xamarin targets?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/reactiveui/ReactiveUI/issues/1983#issuecomment-476308866, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATXZ8ZaKpny9YtgupbvWo9v3XzXnROygks5vaQxsgaJpZM4cHeto.

lackrin commented 5 years ago

https://dev.azure.com/LackrinProjects/_git/ReactiveUITabNavigation Sample APP. Problem is that it works and does not replicate the issue. I have noticed though that the View and ViewModels for the subpage are not being disposed of. I suspect this is the root of my issue, can you please verify?

Files
RLittlesII commented 5 years ago

I will pull this down this evening and see if I can make sense of it. Thank you for taking the time to create the sample. Appreciated.

lackrin commented 5 years ago

Sorry, found issue with slowdown, it was of my own doing. Had an event being added recursively

lackrin commented 5 years ago

Still the Model not disposing is an issue still.