KFP
KFP

Reputation: 719

Windows Phone navigation without creating new instances of Uri

The way I understand Windows Phone 7 navigation is that each time you want to go to another page you use the following:

this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

After going back and forth between pages (4 for example) will this not create a huge amount of objects over time; Being that you are creating a New one each and everytime? Would this turn into an 'out of memory' issue? I just want to make sure I understand the structure of how this works before proceeding further with any development.

Upvotes: 0

Views: 168

Answers (1)

Kevin Gosse
Kevin Gosse

Reputation: 39027

You use NavigationService.Navigate when navigating forward, but NavigationService.GoBack when going back. Therefore, the backstack shouldn't grow indefinitely.

Also, if you need to reach the main page again after a forward cycle (MainPage -> Page1 -> Page2 -> MainPage), it's a good practice to clear the back stack. This way, the user will be able to exit the application with a single press on the back button, instead of going through all the cycle again. To remove a page from the back stack, use NavigationService.RemoveBackEntry():

while (this.NavigationService.BackStack.Any())
{
   this.NavigationService.RemoveBackEntry();
}

Upvotes: 1

Related Questions