Forum Xamarin.iOS

Unload modal page from RAM

VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭

I just run profiler and found problem with modal page with map control. Each time when it shows it occupies around 70MB of RAM. Also when it disappear it doesn't free occupied space.
I used GC.Collect() to free some space, but it doesn't do much. From occupied 70Mb it can free only 15MB in best cases.
Then, when i open that form again it occupies 60MB more and, again, doesn't free them on disappearing.

I'm new with Xamarin.iOS, but i find out, that there are 2 Collectors(.NET GC and iOS reference counting) that doesn't work well;

Can someone help me with that, please?

Page marked up on storyboard. I call it with code below:

public void ShowModal(CustomClass place = null, CustomType type = CustomType.Type1) { var modalVC = Instantiate<ModalVC>(Storyboard.Modal); = place; modalVC.initialType = type; var nav = new UINavigationController(modalVC); _modalNav.PresentViewController(nav, true, null); nav = null; trustedPlaceVC = null; }

also OnViewDidDisappear() i call:

public static Task CollectGarbage() { GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(); GC.WaitForPendingFinalizers(); return null; }


  • JakovljevicIgorJakovljevicIgor USMember ✭✭✭

    Hi @VolodymyrSavchenko you could create a private element in the view controller to reference the modal and when you call the OnDisposing or Dispose methods in the view controller you just call the dispose method on the private element. Maybe this will help you.

    public override ViewWillDisappear(){

    Modal.Dispose(true) --> Something like this
    // Where Modal is the reference to the created modal object

  • JoeProJoePro CAUniversity ✭✭✭
    edited June 2017

    MKMapView uses a lot of memory but since this is managed natively, GC.Collect() will not free any of it up. I have noticed, however, that it does free up it's memory when you start receiving DidReceiveMemoryWarning() messages - which is how memory management should work: release it when it's needed elsewhere.

Sign In or Register to comment.