Skip to content

Commit 41c38c0

Browse files
authored
Fix memory leak by nullifying lifecycleObserver (#98)
## Pull request Please ensure this PR targets the **`dev` branch** and follows the project conventions. CI already runs linting, formatting, and build checks automatically. --- ### Before submitting - [x] This PR targets the `dev` branch (not `main`) - [x] Commit messages follow the semantic-release format - [x] No debug logs or sensitive data included --- ### Summary Fixes a memory leak caused by mapView reference kept by lifecycleObserver --- ### Type of change - [ ] Feature - [x] Fix - [ ] Refactor - [ ] Internal / CI - [ ] Documentation --- ### Scope - [x] Android - [ ] iOS - [ ] JS - [ ] Example App - [ ] Docs --- ### Additional notes There's a memory leak caused by lifecycleObserver apparently because if keeps a reference of mapView. Nullifying lifecycleObserver fixed it for me. The memory leak can be observed by putting GoogleMapsView on a stack or a modal and then closing and navigating to it multiple times. The easiest way to reproduce it is to render GoogleMapsView on a flatlist a few hundred times and to scroll back and forth causing an out of memory crash.
2 parents 2606efa + 7810c49 commit 41c38c0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ class GoogleMapsViewImpl(
813813
if (destroyed) return@onUi
814814
destroyed = true
815815
lifecycleObserver?.toDestroyedState()
816+
lifecycleObserver = null
816817
markerBuilder.cancelAllJobs()
817818
clearMarkers()
818819
clearPolylines()

0 commit comments

Comments
 (0)