C
C#7d ago
Vegas

new command fixing memory leak.

So i have been able to fix memory leak on Windows and forms but cant figure out how todo it with pages. So i am calling specific pages to show inside a frame on button press. Upon changing pages you end up keeping the memory used instead of clearing the data.
private void btn_home_Click(object sender, RoutedEventArgs e)
{
workarea.Content = new Store_My_Client.Pages.Page1();
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
workarea.Content = new Store_My_Client.Pages.Page2();
}
private void btn_home_Click(object sender, RoutedEventArgs e)
{
workarea.Content = new Store_My_Client.Pages.Page1();
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
workarea.Content = new Store_My_Client.Pages.Page2();
}
Any ideas? Thanks
4 Replies
ACiDCA7
ACiDCA77d ago
on what basis do you think you have a memoryleak here
Vegas
Vegas7d ago
when i switch pages back and forth my memory usage keeps going up VS wont let me add a
.Close();

.Close();

to it I have tried
cs workarea.Content = null
cs workarea.Content = null
before it calles the new page but that dont do anything.
ACiDCA7
ACiDCA77d ago
well first, the garbagecollector collects in batches.. meaning you would have to add quite a few instances before it really frees the ram (or wait long enough) second, the memory leak might be inside page1/page2 class and has nothing to do with view switching.. but there is too little info
Vegas
Vegas7d ago
ok thank you