Select to view content in your preferred language

.NET 8 / MAUI 8: Big memory leak in MapView on Android introduced

2062
18
01-19-2024 11:00 AM
Labels (3)
SokoFromNZ
Occasional Contributor

Hello.

The current ArcGIS Runtime v200.3.0 with the current .NET Maui from VS 17.8.5 has a big memory leak which causes our app to crash on a real world Android device just after a few page changes to the map.

I can reproduce this behavior on any real world device. There the app crashes. The emulator though just allocates more and more memory of course.

I have created two simple apps (see ZIP file).
One is MAUI8+v200.3.0 (Map8 in the video).
One is MAUI7+v200.2.0 (Map7 in the video).

You clearly see the memory of the process qemu-system-x86_64.exe (Android Emulator) go up each time the loaded map gets displayed again by almost 1 GByte on the Map8 app.

On the Map7 app it almost stays the same (On the very top of the video you see the Task Manager with the process, CPU and Memory Usage):

All both apps are doing is creating a map and loading 44 KMZ files with a total of 10MByte. Here is the MainPage.xaml.cs:

 

using System;
using System.Threading.Tasks;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Microsoft.Maui.Controls;
using Map = Esri.ArcGISRuntime.Mapping.Map;

namespace ArcGISTry1;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        // Create the UI, setup the control references and execute initialization
        _ = Initialize();
    }

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
    private async Task Initialize()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
    {
        // Set map to mapview
        MyMapView.Map = new Map(BasemapStyle.OSMLightGray)
        {
            InitialViewpoint = new Viewpoint(new MapPoint(11.406534, 47.719954, SpatialReferences.Wgs84), 6000)
        };

        MyMapView.Loaded += OnLoaded;
    }

    private async void OnLoaded(object? sender, EventArgs e)
    {
        for (var i = 0; i <= 43; i++) {
            var dataset = new KmlDataset(new Uri($"http://soko.yourweb.de/kmz/MemoryLeak/{i:00000}.kmz"));
            await dataset.LoadAsync();
            var kmlLayer = new KmlLayer(dataset);
            MyMapView.Map!.OperationalLayers.Add(kmlLayer);
        }
    }
}

 

Those KMZ files are from my production environment and get loaded like this every day by the users which currently use MAUI7.

Please look at this as soon as you can as I have to do another release in February and with this big bug its impossible to do so.

A workaround would help as well if no pre-release is possible until then.

As mentioned already: This is not an Emulator issue! Its just a good and easy way to show/see the problem. After switching pages on the emulator for 1-2 minutes the process used more than 64GByte on my machine.
On the real device (4 and 6 GByte) it only survies a couple a switches....

thanks

Soko

PS: on the Map7/MAUI7 app you have to move your finger over the map after switching back from the notes-page. This is a known bug in ArcGIS 200.2.0 (see my other post for this).

0 Kudos
18 Replies
SokoFromNZ
Occasional Contributor

I have attached the current MAUI8 solution with no errors on my side (sorry about that again) for your convenience.

@PreetiMaske @MatveiStefarov : As dotMorten seems to be busy or sick I would like to ask you guys to look at it quickly and give me confirmation you can reproduce the issue on your side.

I'm forced to release the MAUI8 version of my app in the first half of February. Which I'm unable to do with this bug in it.

I know its not realistic to get it fixed until then. But I still hope there's a workaround you can find...

thanks in advance

Soko

0 Kudos
SokoFromNZ
Occasional Contributor

Hello @dotMorten_esri 

I just saw another memory issue report which you responded to, but it seems there is another issue. Have you had time to review my last example/zip-file?

All I would need at the moment is confirmation of the issue.

Thanks, Soko

0 Kudos
dotMorten_esri
Esri Notable Contributor

The issue is still under investigation.

MatveiStefarov
Esri Contributor

@SokoFromNZ I have not been able to reproduce the memory leak in an Android emulator.  After switching pages repeatedly, I see memory change by at most 2 MB per cycle:

 

2024-03-13_125803 studio64.png

 

I ran your latest updated reproducer, build with ArcGIS Maps SDK 200.3.0 in VisualStudio 17.9.3.  Are you still able to reproduce this with latest-stable versions of MAUI workloads?  Could it be that one of the recent MAUI service releases (8.0.6 or 8.0.7 or 8.0.10) plugged the leaks that affected this project?

0 Kudos
BrianLoehr
New Contributor

Side question - what memory tool generated this image?

0 Kudos
SokoFromNZ
Occasional Contributor

@MatveiStefarov  I will give it a try.

I had no choice than to downgrade to 200.2.0 but leave MAUI at NET8 for our release... which also "solved" (memory still increases but instead of 4 page changes I can do ~100 before it crashes on my hardware device) this problem here. So it is not totally an MAUI issue for sure.

0 Kudos
SokoFromNZ
Occasional Contributor

@MatveiStefarov 

In short

The memory leak is still the same as of the time of the first post here

  • In the emulator via VS debugging
  • In the emulator via APK installation
  • On real hardware via VS debugging
  • On real hardware via APK installation

Do you use my example source? If not: Can you please send me the source code you used to create the graph above?

I have attached my source code below.

Details

I am using the VS versions you mentioned:

VS-NuGet-Versions.png

I am using the plain/standard API34 emulator coming with VS2022:

Emulator.png

I do not have Android Studio installed, only the stuff coming with VS. So here is the video on the emulator using a published APK (using publish.bat in the source attached). The apk you can download here to test it on your emulator or hardware: http://soko.yourweb.de/com.companyname.memoryleak8-Signed.apk 

As you can see at the memory column of the task manager in the background: the memory always increases.

 

In the end though, I really don't care if this is how it is via debugging and/or on emulators. The only thing that counts is a release on a real device.
Thats why I created/published the APK (link see above) and installed the app on the devices the users are using. This video shows the memory leak and the crash on a Samsung Tablet (Samsung SM-P619, Android 14 | One UI 6.0). Same happens on all my devices. The video is too big to have it inline here. So you have to download it to watch: http://soko.yourweb.de/Hardware.mp4 

The RAM Memory Monitor I use in the app can be found here .

 

Suggestions

I'm very curious what makes the issue not reproduceable on your side.

Can you please try to install and run the APK on a real device on your side? I cannot imagine the RAM does not go up steadily on each page-switch.

Can you send me a link to an APK of your set app? I would love to try it on my real device.

Thanks in advance
Soko

PS: If I change the NuGet Package in my csproj from 200.3.0 to 200.2.0 (nothing else) the memory leak is gone. So I do not see how this can be a (sole) MAUI bug...

0 Kudos
SokoFromNZ
Occasional Contributor

@MatveiStefarov Can you please give me an update of your progress here? This bug is still valid with

  • VS 17.9.16
  • <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />
  • <PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" />
  • <PackageReference Include="Esri.ArcGISRuntime.Maui" Version="200.4.0" />

Thomas (from MySynergis) said he has talked to you in person in March in at the Esri event and that you will have a look into it again...we really need a solution for this.

0 Kudos
SokoFromNZ
Occasional Contributor

Hello @MatveiStefarov @dotMorten_esri ,

To the 5 Month anniversary of this bug - which is still blocking our application from publishing - I'd like to ask again about a status update.

Please have a look at my last detailed videos and source and let me know if you can reproduce it on a real hardware device as mentioned.

Soko

0 Kudos