문제 설명
모든 프로젝트 Swift 5에서 1개의 MapView를 공유하는 방법 (How to Share 1 MapView in all Project Swift 5)
전체 프로젝트에서 동일한 MKMapView
변수를 공유할 수 있는지 알고 싶었습니다. 여러 인스턴스를 생성하면 메모리가 상당히 증가하기 때문입니다. MapView로 새 뷰 컨트롤러
를 열자 마자 메모리에 50Mb가 추가됩니다. 뷰 컨트롤러를 닫으면 약 10Mb만 떨어집니다.
맵뷰의 모든 메모리를 해제할 수 있습니까? 아니면 단일 MapView 변수를 생성하고 주석을 생성하기 위해 removeAnnotations를 수행하는 것이 더 낫습니까... 맵 뷰를 변경할 때마다
6var mapview = MKMapView()
viewcontroller
를 닫을 때 다음을 수행합니다. 다른 것이 필요한지 모르겠습니다.)
mapView.removeAnnotations(AllAnnotations)
mapView.delegate = nil
mapView.removeFromSuperview()
참조 솔루션
방법 1:
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