react-native-maps icon indicating copy to clipboard operation
react-native-maps copied to clipboard

Serious memory leak caused by dangling MapMarker views on Android

Open krakowski opened this issue 2 years ago • 4 comments

Summary

My app gets really slow after using the MapView (zooming in & out, moving, etc.) for some time. Looking at the view hierarchy using Flipper revealed that MapMarker views stay in place even after removing them manually and triggering a hot-reload. In my case the default marker is not visible on the map, but the view hierarchy grows indefinitely and causes the whole App to slow down. The patch provided in https://github.com/react-native-maps/react-native-maps/issues/4214#issuecomment-1132214457 seems to be for iOS only. Also, I don't use the Reanimated library.

Reproducible sample code

{ locations.slice(0, 5).map((location, index) => (
    <Marker
      key={index}
      identifier={index.toString()}
      coordinate={{
          latitude: location.latitude,
          longitude: location.longitude,
      }}
      tracksViewChanges={false}
    />
  )
)}

Steps to reproduce

Repeatedly change the slice's length and observe the view hierarchy using Flipper.

Peek 2023-11-17 20-02

Expected result

MapMarker views should be removed from the tree.

Actual result

MapMarker views stay within the view hierarchy.

React Native Maps Version

1.7.1

What platforms are you seeing the problem on?

Android

React Native Version

0.72.6

What version of Expo are you using?

SDK 48

Device(s)

Android 12

Additional information

Converted into an issue from comment https://github.com/react-native-maps/react-native-maps/issues/4214#issuecomment-1816943217

krakowski avatar Nov 17 '23 19:11 krakowski

same issue.

dkahdwk avatar Nov 23 '23 02:11 dkahdwk

Same issue here.

I was on version 1.3.2 and everything was good in Android and iOS, both in dev and production builds.

I updated to Expo 50, it auto updated react-native-maps to 1.10.0 and the issues started... During development:

  • iOS: no issues
  • Android: no issues When I build a prod version
  • iOS: no issues
  • Android: -- map pins and clusters start to flicker a lot, causing 50% of onPress events to be "missed" -- if I leave the app open long enough, I get "Out of memory" errors, crashing the app without any notice

Here's what I get in Sentry when the app crashes (not sure if helps): image

As of now, the only fix I found was downgrading to the version I had, at least I don't see any issues, and I didn't bump into any incompatibilities 🤷

samuthekid avatar Feb 07 '24 11:02 samuthekid

same for me custom markers are flickering before update I had v1.1.0, updated to v1.10.3

only in release mode on android emulators ok

decided to update maps after I got this message to email You may have projects using the legacy renderer that will be decommissioned by March 3, 2025. Apps built with the Maps SDK for Android will be automatically updated to the latest renderer beginning March 4, 2024.

updating to 2.0.0-beta.14 helped me

updating to 2.0.0-beta.14 helped me

It seems this version (https://github.com/react-native-maps/react-native-maps/releases/tag/v2.0.0-beta.14) is pretty old and development for v2 has stopped while v1 still gets new updates. Using the beta version in a production app doesn't seem to be a good idea :confused:

krakowski avatar Mar 04 '24 11:03 krakowski

I can reproduce this issue with the included example project and created a separate example for it. Anyone interested can try my fork including the BUG: Marker causes memory leak (Android) example at https://github.com/krakowski/react-native-maps/tree/bug/marker-memory-leak.

Here's a preview:

https://github.com/react-native-maps/react-native-maps/assets/7255767/46beb33c-e866-480e-baf9-8cda3ebc1e5c

krakowski avatar Mar 04 '24 14:03 krakowski