I have some pages in my app.
When one of my pages is open while
loop creates 1000 buttons (for example).
After I navigate between pages and back to first page Objects (Buttons) creates it again.
I get memory leak. How can I solve this problem?
public sealed partial class BlankPage1 : Page
{
public BlankPage1()
{
this.InitializeComponent();
int i = 0;
while(i < 1000)
{
Button button = new Button();
MainStack.Children.Add(button);
i++;
}
}
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(BlankPage2));
}
}
}