question

Nimalika-6845 avatar image
0 Votes"
Nimalika-6845 asked Nimalika-6845 edited

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

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


windows-uwp
sample-screen.png (476.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichardZhang-MSFT avatar image
1 Vote"
RichardZhang-MSFT answered RichardZhang-MSFT commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the suggestions. I tried those
1. This event got raised several times one time it showed null pointer for one variable initialized in OnNavigatedFrom method. But the variable is initialized in the same method. (Navigated to same screen several times without any issue)

 localStore = new LocalAppDataStore();
 ...
 currentTopicId = localStore.getCurrentTopicId(); (null pointer in this line)

Next time: Cannot create instance of type 'Windows.UI.Xaml.Controls.InkCanvas' (No issue navigating to same screen before the crash)

2. This event didn't get called. Even when app crash AppMemoryUsageLevel showed as "Low"
3. Tried in few screens. But then those screens didn't work as expected. Color changes added with converters didn't work properly. Also null pointer exceptions occurred. 
Any idea why these different exceptions occur only after using the app for some time?

0 Votes 0 ·

Hello, Now you have caught the error that caused the app to crash. If the exception of a null pointer comes out after the application runs for a period of time, check whether the referenced object is released in a certain step, or make repeated references to the same object. These require you to check according to the actual situation of the project. You can create a blank project to extract the logic of possible problems to detect and gradually narrow down the scope of the problem.

1 Vote 1 ·