Skip to content

fix(android): clean up polyline animator on view drop#72

Merged
lodev09 merged 1 commit intomainfrom
fix/android-polyline-animator-leak
May 4, 2026
Merged

fix(android): clean up polyline animator on view drop#72
lodev09 merged 1 commit intomainfrom
fix/android-polyline-animator-leak

Conversation

@lodev09
Copy link
Copy Markdown
Collaborator

@lodev09 lodev09 commented May 4, 2026

Summary

LuggPolylineView.onDropViewInstance previously only cleared the GMS polyline — it never told GoogleMapProvider to dismantle the matching PolylineAnimator. Cleanup of the polylineAnimators map and ValueAnimator.cancel() lived only in removePolylineView, which is reached via LuggMapView.removeViewAt. If a view instance was dropped without that path firing first (e.g. provider/surface teardown ordering), the entire animator chain leaked: an INFINITE-repeat ValueAnimator is held by the system AnimationHandler, keeping the PolylineAnimator, its coordinates, cumulativeDistances, reusablePoints, and the already-removed Polyline alive across re-mounts.

This PR:

  • Adds a polylineViewDidDrop callback to LuggPolylineViewDelegate. LuggPolylineView.onDropViewInstance now notifies the delegate, and GoogleMapProvider routes both removePolylineView and polylineViewDidDrop through a shared teardownPolyline helper.
  • Defensively destroys any pre-existing animator entry at the start of addPolylineViewToMap, so a stale registration can't silently overwrite a still-running ValueAnimator.
  • Drops the per-frame ArrayList(reusablePoints) wrapper in PolylineAnimator.updateAnimatedPolylinePolyline.setPoints copies internally, so the wrapping list is unneeded GC churn.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Test Plan

Stress-tested on Android emulator (Google Maps SDK 20.0.0):

  • 100 animated gradient polylines × 500 coords, full batch remounted every 3 s for ~10 minutes (187 generations). Peak `polylineAnimators` size capped at 105 (100 stress + 4 baseline + 1 transient), zero stale-animator warnings, zero "salvage" cleanups via the `didDrop` path. Java heap oscillated 76–121 MB and recovered to ~45 MB on idle.
  • 1 animated polyline × 10,000 coords, remounted every 3 s for ~2 minutes. Java heap stable at 41–48 MB, native heap stable at 200–214 MB.

Without this fix, the same scenarios would have leaked a `PolylineAnimator` per remount cycle since `onDropViewInstance` ran without the matching delegate notification. The shared teardown helper makes both paths idempotent.

Checklist

  • I tested on iOS
  • I tested on Android
  • I tested on Web
  • I updated the documentation (if needed)

Notify GoogleMapProvider from LuggPolylineView.onDropViewInstance so the
PolylineAnimator (and its infinite-repeat ValueAnimator) gets cancelled
even when the view is dropped without going through removeViewAt. Also
guards addPolylineViewToMap against an already-registered animator entry
and drops a per-frame ArrayList copy in updateAnimatedPolyline.
@lodev09 lodev09 merged commit 378d12e into main May 4, 2026
3 checks passed
@lodev09 lodev09 deleted the fix/android-polyline-animator-leak branch May 4, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant