Reputation: 684
Are all the pages loaded at the beginning of the application? Or are they only loaded when I am navigating towards them? And when I leave a page, are the resources for that page released? Or is there a way I can control it?
Upvotes: 1
Views: 1681
Reputation: 831
Page is an object and is being initialized when you want to navigate to them. Navigating means creating a new Page object and passing it to the Frame's content.
When you call Frame.Navigate, system automatically generates a new Page object of type you have specified. There's an interface called INavigationAware that controls mainly NavigatedTo and NavigatedFrom events. Whenever you navigate TO the page, OnNavigatedTo event handler will be called. Whenever you are navigating FROM the page, OnNavigatedFrom handler will be called. There's also OnNavigatingTo and OnNavigatingFrom events which will trigger before those 2.
You should unregister any event handlers and callbacks in OnNavigatedFrom method in order to prevent unwanted memory leaks. If you have any threads that are running from background thread, do not forget to cancel them as well. When you navigate away from the page that has a thread running on UI thread, your navigation will be queued and will happen after the UI operation completes.
You should read the Application Lifecycle Management MSDN page to get more information about how lifecycle operations can affect Page objects.
Upvotes: 2