Random KVO block crashes when allocating mapView, happens only when open/close screen several times

App is crashing on a map screen when it open and close several times. (Mostly on 6th attempt)

Class that inherits from GMSMapView

class AirportMapView: GMSMapView , AirportMapViewProtocol{

weak var airportMapViewModuleDelegate: AirportMapViewModuleProtocol?

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
 }
override init(frame: CGRect) {
    super.init(frame: frame)
 }
convenience init(from frame: CGRect, with cameraPosition: GMSCameraPosition) {
    self.init(frame: frame)
    self.camera = cameraPosition
 }
  func setCluster() {

    let algorithm = CustomGoogleMapsClusteringAlgorithm.init();
    mapIconGenerator = VJAirportIconGrayClusterGenerator.init()
    let renderer = VJGoogleMapsClusterRenderer(mapView: self,
                                               clusterIconGenerator: mapIconGenerator!)
    clusterManager = GMUClusterManager.init(map: self, algorithm: algorithm, renderer: renderer)
    clusterManager?.setDelegate(self, mapDelegate: self)

 }
}

In ViewController viewDidLoad I am calling init method of mapView

self.mapView = [[AirportMapView alloc] initFrom:frame with:camera];
self.mapView.myLocationEnabled = YES;
self.mapView.settings.compassButton = YES;
self.mapView.settings.zoomGestures = YES;
self.mapView.airportMapViewModuleDelegate = self;

Backtrace of the crash and console logs attached

Observation:

  • GMUClusterManager initWithMap method if I remove addObserver code app is not crashing

After inspecting the Google-Maps-iOS-Utils source code, it turns out that the GMSClusterManager class did not maintain a strong reference to the GMSMapView that it observed via KVO. This could potentially cause crashes if the GMSMapView object ever deallocated before the removeObserver:forKeyPath: method could be called from dealloc.

Per Apple documentation, strong references should be maintained for objects observed via KVO:

Note: The key-value observing addObserver:forKeyPath:options:context: method does not maintain strong references to the observing object, the observed objects, or the context. You should ensure that you maintain strong references to the observing, and observed, objects, and the context as necessary.

See this pull request (which is now merged) for more details.

Random KVO block crashes when allocating mapView , Random KVO block crashes when allocating mapView, happens only when open​/close screen several times #215. Closed. aliakhtar49 opened  1 Random KVO block crashes when allocating mapView, happens only when open/close screen several times Mar 13 '19 View all questions and answers → Badges (11)


I had a similar problem then GMSMapView inside my custom UIView subclass

var mapView: GMSMapView!
var clusterManager: GMUClusterManager!

is deallocated before dealloc in GMUClusterManager and this causes a crash because mapView is going to nil before removeObserver is called So I added

deinit {
    clusterManager = nil
}

to my UIView subclass

Check this thread https://github.com/googlemaps/google-maps-ios-utils/issues/181#issuecomment-385531638

Crash after open/close map multiple times · Issue #181 , after open/close controller with map several times (~3-10 times) i get this crash https://stackoverflow.com/questions/54129679/random-kvo-block-crashes-when-​allocating-mapview-happens-only-when-open-close-s  An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key path: camera Observed object: <GMSMapView: 0x1329e7a00; frame = (0 0; 0


Almost the same crash here ... it disappears when i changed clusterManager from strong property to stack object

Firebase iOS Release Notes, Random KVO block crashes when allocating mapView, happens only when App is crashing on a map screen when it open and close several times. (Mostly on  **Platform:Android 7.0 **Mapbox SDK version:5.2.1 Steps to trigger behavior Create Mapview in Fragment Open mapview Close mapview Expected behavior Mapview closed Actual behavior App generates ANR and crashes after some seconds If I grey


Using Combine, Random KVO block crashes when allocating mapView, happens only when App is crashing on a map screen when it open and close several times. (Mostly on  MKMapView *mapView = [[MKMapView alloc] init]; I have never been able to reproduce this crash, but it has occured hundreds of times for my users. It seems to happen repeatedly for certain users. From the data available it appears this crash only happens on iOS 8 and specifically versions <8.3.


Changelog, Developers should remove pod Firebase/InAppMessagingDisplay and only use pod Support for the open source libraries is now included in the zip and Carthage Fixed the documentations on a few random generation and hash methods to Fixed a crash that could happen when the app is shut down after a write has  Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.


Many of the pipelines you create with Combine will only be a few what processing should happen to a stream of values over time. .publisher on KVO instance For any type of UI object (UIKit, AppKit, or SwiftUI), Assign can be used The operator will cause the application to terminate (or tests to crash  removing a mapView on android - crash - posted in General Questions/Discussion: Hello, When exiting a scene i want to remove the mapObject that has been created, so the native map isnt visible in other scenes. The code i am using is: function mapScene:exitScene( event ) nativeMap.parent:remove(nativeMap) nativeMap = nil end mapScene:addEventListener(exitScene) On an iPhone or iPad this code