Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapview leak memory on IOS #2782

Closed
kduy969 opened this issue Apr 2, 2019 · 34 comments

Comments

Projects
None yet
@kduy969
Copy link

commented Apr 2, 2019

Version: branch master, commit 21a7536
React native version: 0.59.1
Platform: IOS
Map Provider: Google.

Issue:
Each time I open a screen which contain a <MapView/> , memory go up about 50mb, but when I go back , memory not reduce the same amount ,try this a few times will make app crash. After that, I use Xcode profile tool to monitor leak event, this point out leak memory come from AIRGoogleMap[getActionForTarget] , despite I have no marker on MapView. When I remove <MapView/> from my screen, the issue gone away.

PS: I switch to master when trying to workaround a bug mentions here:
#2737 (comment)

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

isn't this duplicate of #2775 ?

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

Anyway, I'm also encountering some weird behaviour on iOS... On Android, everything works just perfect and smooth (even on emulator device). But on iOS with iPhone XR (The fastest Apple Bionic A12 chip) and release build, react-navigation transition is very laggy when I'm entering or leaving Map Screen.

I don't know if this is problem of react-navigation or react-native-map, but I'm using most current versions of react-native, react-native-maps and react-navigation.

@rborn

This comment has been minimized.

Copy link
Collaborator

commented Apr 2, 2019

@kduy969 thanks for this, please have a look at #2775 (what @sinodko said) and see if the same case and maybe add your findings to it.

(it has more details and info so we'll switch to that issue for this bug)

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

@rborn can this memory leak be also related to the problem that I'm encountering?

@rborn

This comment has been minimized.

Copy link
Collaborator

commented Apr 2, 2019

@sinodko it might be this only if the lag starts after you enter/leave the map multiple times ( and assuming the leak is not related to the tiles which would do show on zoom or region chnage)
If it happens right away I don't really know what's going on.

Do you have this issue on any other device?

Maybe you're doing something fancy (like re-rendering multiple times or building stuff on an event that triggers often - like onRegionChange) ?

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

I'm making SQLite call on componentDidMount which is fetching markers (there can be even 500+ markers) so there is some heavy liftings. I will take a look at number of renders in the component but the weird thing is that on mid-upper range android device is everything working smoothly but on top level iOS flagship (in terms of processor and power) the transition is crispy.

If I run SQLite query after transition is complete, then transition is more smooth. But then on "back" transition the performance is laggy again.

I will take a deeper look on that and if I'm not able to make it smooth I'll probably open new issue with additional info :)

@rborn

This comment has been minimized.

Copy link
Collaborator

commented Apr 2, 2019

500 markers? this is a lot

I'd suggest to implement some clustering and/or exclusion based on the zoom level and current region to reduce the number.

Can you try to use Instruments on the app maybe you find where the memory goes bonkers?

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

I'm using the react-native-maps-super-cluster package for clustering and the performance on map is just fine even on old xperia Z2 during map moving/zooming. I'm even using onRegionChangeCompleted to recompute visible markers by viewport of the map widget - :) The problem only appears when I'm entering or leaving the map even when I open the Map which contains only 1 marker.

@rborn

This comment has been minimized.

Copy link
Collaborator

commented Apr 2, 2019

@sinodko apple map or google ? (maybe we can narrow the issue)

@sinodko

This comment has been minimized.

Copy link

commented Apr 2, 2019

@rborn Google Maps. I wanted to use AppleMaps but there was a problem with onRegionChangeCompleted firing while using custom tiles (only in offline mode) so I decided to go with Google Maps instead.

@ottoo

This comment has been minimized.

Copy link

commented Apr 3, 2019

Use 558b34c icon property on markers instead of the image property. This made a huge difference.

@kduy969

This comment has been minimized.

Copy link
Author

commented Apr 3, 2019

@sinodko @rborn this may be same problem with #2775 , it's happen on Google Map too , the only difference is I don't have any marker on MapView. Every time I open screen with MapView , i see a leak memory event in Xcode profile tool, and the memory chart only going up after multiple open/close.

@sinodko

This comment has been minimized.

Copy link

commented Apr 3, 2019

@ottoo even when I'm using only default markers with their default look?

@rborn rborn added bug iOS labels Apr 3, 2019

@ottoo

This comment has been minimized.

Copy link

commented Apr 3, 2019

@sinodko

No, we're using custom markers.

@rphlmr

This comment has been minimized.

Copy link

commented Apr 7, 2019

Same issue here, ram increase on ios every time I open a screen with a MapView (google provider). I'm using the master branch off react-native-maps to fix issues on Android graddle build.

@eyu0415

This comment has been minimized.

Copy link

commented Apr 8, 2019

Same issue here(google provider)
In my case,
react-native: 0.59.3
react-native-maps: github:react-community/react-native-maps

If I push the scene contain MapView, memory increased around 0.09GB.
and pop the scene the allocation was not freed.
If I push same scene again, memory increased again without.
memory leak

**

I solved this issue with react-native-maps: 0.23.0

스크린샷 2019-04-08 오후 3 06 56

@sinodko

This comment has been minimized.

Copy link

commented Apr 9, 2019

I'm also encountering around 100MB of memory leak after the map is opened and then closed.

EDIT: Sometimes the number even goes higher. Like 250mb of leak with just one open-close cycle

EDIT2: I'm using latest rc version of react-native-maps. Commit number #6c225af612d4681a00d4849b60774d7c6426835e

@sinodko

This comment has been minimized.

Copy link

commented Apr 9, 2019

@eyu0415 can I use 0.23.0 with react-native 0.59.x?

@rphlmr

This comment has been minimized.

Copy link

commented Apr 9, 2019

@sinodko For iOS only, I think. For android, no.

@eyu0415

This comment has been minimized.

Copy link

commented Apr 9, 2019

@eyu0415 can I use 0.23.0 with react-native 0.59.x?

Sure, I used react-native 0.59.3 & react-native-maps 0.23.0

@sinodko

This comment has been minimized.

Copy link

commented Apr 12, 2019

Memory leaks persist even with react-native-maps version 0.24.0

@jramalho

This comment has been minimized.

Copy link

commented Apr 12, 2019

@sinodko For iOS only, I think. For android, no.

in Android too.

#2807

@todtod80

This comment has been minimized.

Copy link

commented Apr 13, 2019

It's still occurring in 0.24.0

@kletan

This comment has been minimized.

Copy link

commented Apr 14, 2019

I experience the same issue. No problem with Apple Maps, but when switching provider to Google the RAM memory increases steadily until it reaches about 1,6gb and crashes application.

@ntelkedzhiev

This comment has been minimized.

Copy link

commented Apr 15, 2019

I noticed a similar behavior on Android.

Android: 9.0
react-native: 0.59.4
react-native-maps: 0.24.0

The app crashed once the MapView loads the actual map. I experience it on the emulator but not on a real device. Maybe the reason is that my emulator has less RAM.

@sinodko

This comment has been minimized.

Copy link

commented Apr 16, 2019

Hope this will get solution soon. Feeling so helpless because I can't even read Objective C 😄

@christopherdro

This comment has been minimized.

Copy link
Collaborator

commented Apr 16, 2019

I just published 0.24.1 with the following commit(90e4a6e) that should resolve the memory leak issue. Can you guys test and confirm?

@rphlmr

This comment has been minimized.

Copy link

commented Apr 16, 2019

@christopherdro Thanks for the commit.
I still have the issue with "react-native-maps": "https://github.com/react-native-community/react-native-maps/archive/v0.24.1.tar.gz" :(

@christopherdro

This comment has been minimized.

Copy link
Collaborator

commented Apr 16, 2019

@rphlmr Can you try and use the instruments tool to see if you can confirm the issues are coming from this library?

@rphlmr

This comment has been minimized.

Copy link

commented Apr 16, 2019

@chrisknepper I'm totally new about that 😂
I don't know what i'm seeing, tell me if it's useless
Capture d’écran 2019-04-16 à 23 55 02

We can clearly see the problem on this :
Capture d’écran 2019-04-17 à 00 32 52

If I comment AIRGoogleMap.m like this :

- (void)didPrepareMap {
  UIView* mapView = [self valueForKey:@"mapView"]; //GMSVectorMapView
  //[self overrideGestureRecognizersForView:mapView];

Memory leek disapear.
Something to look in overrideGestureRecognizersForView, but I didn't know anything about objective c ^^

@sinodko

This comment has been minimized.

Copy link

commented Apr 17, 2019

@christopherdro I can confirm that memory leak still persist on 0.24.1 patched version :( still around 150-200MB leak after every time that Google Map is opened on iOS.

// EDIT - I can also confirm that @rphlmr hack from previous comment is working for me too.

@christopherdro

This comment has been minimized.

Copy link
Collaborator

commented Apr 17, 2019

Just published 0.24.2 with the following fix #2818

@rphlmr

This comment has been minimized.

Copy link

commented Apr 17, 2019

@christopherdro @ukrbublik Thank you, it works !!!

@rborn

This comment has been minimized.

Copy link
Collaborator

commented Apr 18, 2019

closing as per #2782 (comment)

@rborn rborn closed this Apr 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.