UWP Windows 10 App memory increasing on navigation

后端 未结 3 1050
無奈伤痛
無奈伤痛 2020-12-25 11:09

I have a UWP Windows 10 App and noticed the memory usage in task manager is increasing over time.

I stripped the App back and found the memory is increasing when the

相关标签:
3条回答
  • 2020-12-25 11:47

    I have seen the same problem on w8.1 with printingInline using charmBar it's consuming a lot of memory until crash of the application (1.5 GB). but normaly you don't need GC.colect() it's work automaticly .

    0 讨论(0)
  • 2020-12-25 12:06

    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()
    0 讨论(0)
  • 2020-12-25 12:09

    Can we see your xaml code? Are you using x:name in your xaml and is that being destroyed? If so that might cause your memory leak.

    Look at this link if you are using x:name: http://support.scichart.com/index.php?/News/NewsItem/View/21/wpf-xname-memory-leak--how-to-clear-memory-in-scichart

    Of course a UWP may handle x:name differently...

    0 讨论(0)
提交回复
热议问题