UWP App crash at different screens when using it for a long time

Nimalika 21 Reputation points
2020-06-18T07:51:55.21+00:00

In our UWP app we have XAML screens with ListView, Grid, ScrollView, ItemsControl like UWP elements. To show HTML content we use Web views. We have images also on each screen.

All screens work as expected when app open initially. But after using the app for some time app gets crashed on different screens.

We monitored the app using Visual Studio Performance profiler also. When using the app, memory keeps increasing. But it didn't always crash when it reaches a particular value. We checked the app with and without images.

With images, it crashed when reached 989 MB
Without images, it crashed when it reached 467 MB.

It doesn't crash on the same screen. Page navigation happens a lot in the app. Also, we load a lot of listview items and item control items (with web views) on each screen.

Is there a maximum allowed object count or something like that in UWP apps? We were not sure this crash happens due to memory increase. But we noticed there is no specific value (MB) that it gets crashed. What could be the reason for this random crash issues?

10427-sample-screen.png

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-06-18T08:36:24.19+00:00

    Hello,

    Welcome to Microsoft Q&A.

    The crash of the application may be caused by various reasons, you need to check according to the actual situation.

    1. Handle the UnhandledException event.

    You can try to listen to the UnhandledException event in App.xaml.cs to confirm whether there is an uncaught exception that causes the application to crash.

    2. Handle the AppMemoryUsageIncreased event.

    From your description, the application may be terminated because the memory exceeds the limit. In order to determine this, you can listen to events related to memory usage based on the content of this document and process them. UWP is not designed to use system resources indefinitely, so when the AppMemoryUsageIncreased event is triggered, you can manually release some resources to reduce the application's memory usage.

    3. Cache page

    In frequent page navigation, caching pages is usually an effective approach.

    public MyPage()  
    {  
        this.InitializeComponent();  
        NavigationCacheMode = NavigationCacheMode.Enabled;  
    }  
    

    After caching the page, when navigating to that page again, the cached page will be used first instead of creating a new page. Cache the pages you use frequently to avoid repeated page construction, which will effectively reduce your memory usage.

    Thanks.

    1 person found this answer helpful.