Search code examples
swifthere-api

MSDKUI 2.1.1 Swift - Memory issue


I segue into a view controller in which I have the following views: NMAMapView GuidanceManeuverView GuidanceSpeedView GuidanceSpeedLimitView GuidanceEstimatedArrivalView TravelTimePanel GuidanceNextManeuverView and is also a NMAMapLoaderDelegate I create a map route and display that when the ViewController is displayed.

I segue out of this view controller with the back button - this is all in a Navigation Controller, and the view controller should be deallocated when I segue out of it, however it is staying in memory. Each time I segue into this view controller I create a new view controller and the old view controllers are still active in memory. Because of this after about the 10th time the view controller with the NMAMapView is loaded the app crashes out of memory.

Is there a method that I am supposed to call or something that I am supposed to do to ensure that this view controller is deallocated when I back out of it? Or am I supposed to re-use the view controller?


Solution

  • I found the issue which came from some HERE example code for function "findCurrentPosition()"

        private func findCurrentPosition() {
            guard positioningManager.startPositioning() else {
                print("Error: Positioning failed to start.")
                return
            }
    
            // Subscribe to position updates.
            var token: NSObjectProtocol?
            token = NotificationCenter.default.addObserver(
    

    The "token" above is a strong reference. To fix it I changed it to a weak reference

            token? = NotificationCenter.default.addObserver(