mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
622 stars 319 forks source link

StrictMode: A resource was acquired at attached stack trace but never released #6264

Closed TianyiMu closed 1 year ago

TianyiMu commented 2 years ago

Android API: API 26 Mapbox Navigation SDK version: 2.6.0

Steps to trigger behavior

  1. Open activity with map view added via code
  2. Opens fine and then close activity, do not leave app
  3. Opens the activity again to observe crash

Inside activity layout xml

<FrameLayout
      android:id="@+id/map_container"
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

Inside activity onCreate

mapView = MapView(
            activity,
            MapInitOptions(
                context = activity,
                resourceOptions = ResourceOptionsManager.getDefault(
                    activity.applicationContext,
                    TOKEN
                ).resourceOptions,
                styleUri = Style.MAPBOX_STREETS
            )
        )
        binding.mapContainer.addView(mapView)

We also added MapView lifecycle methods

Expected behavior

No crash

Actual behavior

E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
    java.lang.Throwable: Explicit termination method 'dispose' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:223)
        at android.view.DisplayEventReceiver.<init>(DisplayEventReceiver.java:95)
        at android.view.Choreographer$FrameDisplayEventReceiver.<init>(Choreographer.java:845)
        at android.view.Choreographer.<init>(Choreographer.java:225)
        at android.view.Choreographer.<init>(Unknown Source:0)
        at android.view.Choreographer$1.initialValue(Choreographer.java:108)
        at android.view.Choreographer$1.initialValue(Choreographer.java:102)
        at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
        at java.lang.ThreadLocal.get(ThreadLocal.java:170)
        at android.view.Choreographer.getInstance(Choreographer.java:251)
        at com.mapbox.maps.renderer.MapboxRenderThread.prepareRenderFrame(MapboxRenderThread.kt:353)
        at com.mapbox.maps.renderer.MapboxRenderThread.processAndroidSurface$sdk_release(MapboxRenderThread.kt:417)
        at com.mapbox.maps.renderer.MapboxRenderThread$onSurfaceCreated$1$1.invoke(MapboxRenderThread.kt:424)
        at com.mapbox.maps.renderer.MapboxRenderThread$onSurfaceCreated$1$1.invoke(MapboxRenderThread.kt:423)
        at com.mapbox.maps.renderer.RenderHandlerThread.postDelayed$lambda-1$lambda-0(RenderHandlerThread.kt:26)
        at com.mapbox.maps.renderer.RenderHandlerThread.$r8$lambda$dQbKYthTGCKC4qKFKD3ersIQHak(Unknown Source:0)
        at com.mapbox.maps.renderer.RenderHandlerThread$$ExternalSyntheticLambda0.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.os.HandlerThread.run(HandlerThread.java:65)
cafesilencio commented 2 years ago

cc @mapbox/maps-android

yunikkk commented 2 years ago

Seems its the same as this maps ticket - https://github.com/mapbox/mapbox-maps-android/issues/942

cafesilencio commented 1 year ago

Since this is being tracked as a maps issue and isn't an issue with the navigation SDK I'm closing this ticket. The maps issue is being tracked here: https://github.com/mapbox/mapbox-maps-android/issues/942.