Every time you navigate to a Page, you create a new instance of Page, but the previous Page is not disposed (even if the Page is already in the navigation stack).
To prevent multiple allocation of same page, set NavigationCacheMode="Enabled"
attribute to the Page.
Also, to minimize the memory allocation, you must override method OnNavigatedTo
and OnNavigatedFrom
.
In OnNavigatedTo
method:
- Instantiate all memory intensive object or resources
- Add all events handlers you need
- starts all timers, tasks or threads
In OnNavigatedFrom
:
- Dispose all resources
- Stops all timers, tasks or threads
- Remove references from all heavy objects
- Remove all events handlers
- Only if you really need, call GC.Collect()