Select to view content in your preferred language

MapView Memory Leak? Maui .Net 8 / Runtime 200.4.0

423
6
Jump to solution
06-10-2024 01:27 PM
Labels (3)
Benjamin1
New Contributor II

Good Afternoon,

We are currently in the process of moving a WPF app to Maui. 

Version -

200.4.0 ESRI Runtime Maui

 Maui 8.0.40

.NET 8 - current release

C#

MVVM

No Toolkits

The application uses a mixture of online / vtpks / hosted layers / graphic layers / custom location datasource. Ability's of navigation / panning / selection / switching maps / no editing

I've listed the above to give an idea of what functionality is in use.  

The issue we are currently seeing is memory growth when minimizing or logout/login. As an example using the ios graphics hub overview. Upon logging out/in or background / foreground noticing memory increase each time this happens till eventually the app crashes due to memory.  Memory growth varies but generally around 100mbs each load. 

This application does have a login view then proceeds to the map view. Upon logout the map view is disposed along with disposing of view / map view / maps / layers / graphics / location datasource / event handlers / etc.  Disposing as in clearing and setting null / removing references. Upon reentry breaking at points of recreation the mapview / map / controller / location data / graphic overylays appear to be null and checked before recreation. The map view itself is presented as a Transient view using dependency injection. 

I generally assume it's something within the custom code that is causing the leak whether something is not properly disposed however cycling through this many of times, every object seems to be.  I'm reaching out because this one has me stumped and an understanding that Maui and ESRI Maui runtime is still fairly new with fixes quite often. I've searched through the community and online. Have seen a few similar post but not really any defined issues nor work arounds / fixes.  I've not seen any known issues on this as well. Any help, links or information inside this scope is greatly appreciated. 

Also I did not post code being I'm not certain what would help in troubleshooting. If something in particular needs to be looked at I can post. 

0 Kudos
1 Solution

Accepted Solutions
Benjamin1
New Contributor II

The Maui update to 8.0.60 resolved the memory leak I was seeing. Thank you again dotMorten for your time. 

View solution in original post

0 Kudos
6 Replies
dotMorten_esri
Esri Notable Contributor

Do you only see the memory issue on iOS?

Is so, do you happen to be using a Toolbar in your app? There are a couple known toolbar memory issues preventing the entire page from getting garbage collected:

They were both fixed in the last week or so, so if you're up for trying out the nightly builds of MAUI that might help confirm/deny if you're hitting this issue.

 

0 Kudos
Benjamin1
New Contributor II

Thank you for replying.  We do not use a toolbar within the app. 

We do have collection views, which I did see they fixed memory leaks previous 8.0.40.  Though this seems to be pointing towards the map view.  Maybe I'm off with this, but on the iPad using the Developer tools -> Graphics Hub appears to be linked with the map view only.  I can watch and see as I do certain things like zooming in / out / changing basemaps the memory usage going up and down as expected.  Upon reentry however it grows each time.  Once around 2-3gigs it simply crashes.

Just to add a bit more to this as an example of what I am seeing.  All views have their own corresponding View Models. A Main Page singleton. Login View, Map View, Loading View are all transient.  Using Shell to navigate. Always cycling back through the original Main Page upon view change. 

View Changes would look something like this. 

Login View -> Map View (Logout) -> Login View

Login View -> Map View (Background) -> (Foreground)Load View -> Map View

Upon either logging out and in or background/foreground.  The second time the Map View is created we see memory growth. It appears to be only on loading the map view again.  During operation of the app, changing basemaps / loading layers / etc does not appear to hold on to memory. It seems to be centric around the creation of the view again only.  Each time increasing.  As far as I can tell the mapview / map / layers / graphicslayers / location data source / events are being cleared disposed unreferenced during the transitional phase between either logging out or background.  Upon reentry checks are there as well to make sure those objects are null before reinitializing.  Those checks do not trigger as expected. 

0 Kudos
dotMorten_esri
Esri Notable Contributor

Maui just released a service release with a bunch of memory leak fixes: https://github.com/dotnet/maui/releases/tag/8.0.60

If any view on a page leaks, it'll end up holding on to the entire page, including the mapview, and there's not much we can do to overcome that. If the above update doesn't help, you could actually removing the entire mapview control from the page when navigating away. It won't fix your memory leak, but it'll at least get rid of the largest amount of memory being leaked.

0 Kudos
Benjamin1
New Contributor II

Yes, I saw this earlier.  I will give this update a try and look into removing the mapview control when navigating away.  Will update on what I find. Thank you for responding. 

0 Kudos
Benjamin1
New Contributor II

The Maui update to 8.0.60 resolved the memory leak I was seeing. Thank you again dotMorten for your time. 

0 Kudos
dotMorten_esri
Esri Notable Contributor

Thanks for confirming. Great to hear those fixes helped you too (our sample viewer has been hurting because of the same issue)

0 Kudos