0

I have try to develop UWP App, but i have find many problems with memory leaks, using simple project when switch from page to other page the memory is not free using visual studio diagnostics. Other user have same problems?

for reproduce the problems i have prepared a sample project

http://www.fasthomestore.it/UWPNavigation.zip

Compile, start project, start visual studio diagnostic, wait 30 minutes, the memory increase continually

Luca
  • 11
  • 1
  • Possible duplicate of [Do all UWP apps leak memory when navigating pages?](https://stackoverflow.com/questions/49831807/do-all-uwp-apps-leak-memory-when-navigating-pages) – ClaudiuC_MSFT Sep 25 '19 at 09:07

1 Answers1

0

You may need to set the NavigationCacheMode to Required or Enabled, by default, this value is Disabled which means The page is never cached and a new instance of the page is created on each visit.

public SecondPage()
{ 
    this.InitializeComponent();
    this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;
     ...
    //this.Unloaded += SecondPage_Unloaded; 
} 

private void OnTick(object sender, object args)
{
    //_timer.Stop();
   ...
}

This will not create a new instance each time the page navigate. More details please reference Page.NavigationCacheMode property.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • What if I don't want to cache the page. How can I call garbage collector to release memory? – Arsman Ahmad Aug 22 '19 at 07:45
  • You could call GC.Collect on the OnNavigateTo function of the page, for more on this, read https://learn.microsoft.com/en-us/dotnet/api/system.gc.collect?view=netframework-4.8 – Skynet094 Sep 21 '19 at 10:08