mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Mobile browsers crash after loading/unloading a few maps

Open jnorris441 opened this issue 10 years ago • 8 comments

v0.24.0:

Steps to Trigger Behavior

  1. Load a map in a page container div
  2. Remove the container from the DOM (as in a React page transition)
  3. Repeat 3-6 times

Expected Behavior

No crash

Actual Behavior

The tab will crash on mobile Safari and Chrome on Android. Is it required that we call map.remove() or is that done automatically?

jnorris441 avatar Sep 27 '16 17:09 jnorris441

These crashes are likely due to allocating too many WebGL contexts on a page. Calling Map#remove will release the WebGL context and allow you to delete / create maps indefinitely.

Please re-open with a demo if Map#remove doesn't solve your problem.

lucaswoj avatar Sep 27 '16 18:09 lucaswoj

@lucaswoj map.remove() on componentWillUnmount() did not solve the issue for me.

In this fiddle, reloading 9 times causes a crash in iOS: https://jsfiddle.net/jnorris441/24rgc7L4/1/

jnorris441 avatar Sep 27 '16 18:09 jnorris441

I'm not seeing a crash, since I'm not on a mobile device, I guess. But what I'm seeing is increased memory usage after each reload. It seems that there are several severe memory leaks. After reloading five times the JS heap grew from 52MB to 78MB.

Could it be that the mobile device is just running out of RAM for the browser?

kitten avatar Sep 27 '16 19:09 kitten

@philpl That sounds likely

jnorris441 avatar Sep 27 '16 19:09 jnorris441

@philpl @jnorris441 did you guys ever identified the cause / fix for this leak? we're running into a similar issue here https://github.com/uber/react-map-gl/issues/167

abmai avatar Jan 09 '17 08:01 abmai

@abmai I don't have any insights on hand. This could be a memory leak in GL JS, WebGL, or Chrome. Have you run the Chrome memory profiler on your use case?

lucaswoj avatar Jan 09 '17 19:01 lucaswoj

@lucaswoj - I only quickly used the timeline to ascertain of a leak. will do some deeper digging and send updates in the react-map-gl issue I linked

abmai avatar Jan 09 '17 20:01 abmai

Thanks @abmai. I'll follow the linked issue.

lucaswoj avatar Jan 09 '17 23:01 lucaswoj