Memory Leak in the Xamarin Forms Maps component on iOS

TonyTruppTonyTrupp USUniversity ✭✭
edited April 2016 in Xamarin.Forms

I've been using the Xamarin.Forms.Map on a project, but it looks like there might be a memory leak within the component.

When inspecting memory usage with the profiler, every time I navigate back to the page with the map, memory usage jumps up a lot, like it's never being garbage collected, even after the page that it was added to has been popped off the navigation stack.

As a proof of concept I made this really simple two page forms app (attached). (Note that I didn't set this up to work on android, so not sure if it's an issue there too)

If it is a problem with the component itself, could Xamarin please provide a fix?

Posts

  • TonyTruppTonyTrupp USUniversity ✭✭
    edited May 2016

    Has anyone from Xamarin had a chance to look into this map component memory leak issue yet? It jumps up by about 80mb every time that map component is used.

    Here's a screenshot from the profiler, notice how it jumps up each time a page with the map is opened:

  • GaryMcGheeGaryMcGhee AUMember ✭✭

    Check the notes for each version here : https://www.nuget.org/packages/Xamarin.Forms.Maps/2.3.0.49
    They do seem to have fixed some memory leaks, but I am seeing similar loss to you when navigating away and back to a page with XFM on Android with a custom renderer I didn't develop.

  • CalvinFongCalvinFong USMember ✭✭

    I'm experiencing this on Android. Did anyone find a quick fix to free up the memory?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    There is a bug report about this:
    https://bugzilla.xamarin.com/show_bug.cgi?id=40970
    also for Android: https://bugzilla.xamarin.com/show_bug.cgi?id=39489

    There is a workaround noted in both of those reports (basically the same workaround):
    iOS: https://bugzilla.xamarin.com/show_bug.cgi?id=40970#c13
    Android: https://bugzilla.xamarin.com/show_bug.cgi?id=39489#c3

    Guide on creating a custom map renderer to use the workaround:
    https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/

    Android side should be fixed in the upcoming Forms 2.3.4 release.

  • JoFallasJoFallas USMember ✭✭

    Hello there!

    @JGoldberger it's there any improvement about this issue in iOS platform?
    I have already updated the Forms and the Forms.Maps version without success results.

    Thanks in advance!

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @JoFallas

    I have no idea. According to the bug reports the issue is fixed. Are you forcing Garbage collection to mke sure that the increasing memory is not just normal behavior until the garbage Collector runs (which won't happen until memory is needed to be reclaimed)?

    In fact the iOS side of this bug did not end up being a bug, only the Android side was really leaking. On the iOS side it was just a misunderstanding of when the GC will run and deallocate those pages. There are some private comments on the bug report that go into more detail, but the end result for iOS is that if you are not forcing garbage collection with GC.Collect() then memory will grow until the garbage collector runs. Garbage collection is an expensive process so ultimately should not be run manually unless needed, so if your iOS app is not running out of memory then you should juts let the garbage collector run when it decides to run based on memory pressure.

Sign In or Register to comment.