Fabio Silva Lima

Fabio Silva Lima

  • NA
  • 4.1k
  • 1.2m

New instance every time using NavigationPage Xamarin Forms?

Dec 2 2016 5:00 AM
Let's say i have 3 Xaml views and i use a MasterDetailPage and NavigationPage to navigate back and forward to those pages. Page A -> Page B -> Page C -> ...
I use PushAsync to perform the navigation. No big deal...
I implemment that in two ways:
1 - Create a new instance of those views every time on navigation:
  1. await Navigation.PushAsync(new Views.PageA());  
 
2 - Create a static property (at App view) for each page and i use that for navigation:
 
  1. public static Views.PageA PageA   
  2.     {  
  3.         get  
  4.         {  
  5.             if (_pageA == null)  
  6.             {  
  7.                 _pageA = new Views.PageA();  
  8.             }  
  9.   
  10.             return _pageA =;  
  11.         }  
  12.     }  
  13.   
  14.   
  15. await Navigation.PushAsync(App.PageA);  
 
Is there another way to do that? Use static or new instance every time?
My concern it's about performance and memmory usage.
Please let's your answear with your opinion and some code will be apreciated.