mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
472 stars 131 forks source link

Warning spam in log when animating point annotations after style change (memory leak) #2207

Open tukez opened 1 year ago

tukez commented 1 year ago

Environment

Observed behavior and steps to reproduce

I am animating point annotations (using PointAnnotationManager), but after I load a new style the log gets spammed with

13:01:10.665 14950-15184 chatty                     I  uid=10079 GEOJSON_PARSER identical 11 lines
13:01:10.668 14950-15184 Mapbox                     W  [maps-android\Mbgl-Style]: Style object (accessing setStyleGeoJSONSourceData) should not be stored and used after MapView is destroyed or new style has been loaded.
13:01:10.672 14950-15184 Mapbox                     W  [maps-android\Mbgl-Style]: Style object (accessing setStyleGeoJSONSourceData) should not be stored and used after MapView is destroyed or new style has been loaded.

Expected behavior

No log spam.

Notes / preliminary analysis

The animations are constantly moving the annotations on the map. I use Android's ValueAnimator which calls

annotation.point = valueAnimator.animatedValue as Point
annotationManager.update(annotation)

I am not calling setStyleGeoJSONSourceData anywhere by myself.

As soon as I stop the animations, the log spam stops.

If I never load a new style, there is no log spam.

tukez commented 12 months ago

This warning logging is caused by the annotation manager's source, it does not update the style delegate when a new style is loaded.

tukez commented 12 months ago

Workaround for this is to remove and recreate the annotation manager and all its annotations when the style changes.

If you use clustering, do not pass clustering options when recreating the manager. Associated bug: https://github.com/mapbox/mapbox-maps-android/issues/2209