Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Share 1 MapView in all Project Swift 5

I wanted to know if it was possible to share the same MKMapView variable in the whole project.
Since creating multiple instances is increasing memory considerably.
As soon as I open a new view controller with just a MapView, it adds 50Mb to memory. And when I dismiss that view controller it only drops about 10Mb.

It is possible to free all the memory of the mapview?. Or is it better to create a single MapView variable and be doing removeAnnotations to create annotations… every time change the map view

var mapview = MKMapView()

When dismiss viewcontroller I do this: (I don’t know if anything else is needed.)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

mapView.removeAnnotations(AllAnnotations)
mapView.delegate = nil
mapView.removeFromSuperview()

>Solution :

Yes creating many items causes memory gets high even if deinit is called , so you make 1 global map

import MapKit 
let map = MKMapView(frame:CGRect.zero)

and when you need to show it in a vc , add it to view with constraints and after leaving remove it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading