-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Memory usage doesn't come down when the map is removed/unmounted from the DOM #9126
Comments
Hi @iamanvesh - thanks for using Mapbox & for the detailed report! You say this is not Safari-specific, you're seeing the same issue in Chrome? I assume you've observed/tested this only on Mac and not other platforms? I wasn't immediately able to reproduce on Linux Chrome but we'll investigate on Mac and see what we can see. |
@vakila I've seen similar trend on chrome (mac) but the retained memory is negligible. These stats are from Safari. Also, please test the react app, although both the samples do the same, I observed that the react app tends to take some extra time to clean up the used memory. |
@kkaefer Just some more info in addition to provided by @iamanvesh |
I've updated the issue description, our style has more than 100K features spread across the USA. |
Hi, another thing thats probably valuable to doublecheck is if leaks caused by the Safari Web Inspector itself, I have been bitten by this in the past. Sometimes just closing the Web Inspector ends up releasing a bunch of memory. |
I've tried running the same test with just the activity monitor. Getting similar results more or less. |
@arindam1993 @kkaefer Have you guys made any progress on this issue? |
@iamanvesh We have been able to verify that there is a small leak related to creating and destroying maps in Safari and are investigating the root cause. We'll update here when we have additional information or questions. |
@asheemmamoowala Any update on the issue? |
Im seeing this issue still in mapbox 1.7.0, if i create a map, do a map.remove(), create the same map again and repeat this cycle memory useage grows quickly, and even waiting for GC ticks on each cycle average memory usage still continuously grows |
Able to reproduce this on Chrome with mapbox-gl v1.7.0. Just observing the Task Manager shows a sustained ~100-200mb jump in memory usage that doesn't get GC'd every time a Mapbox gets instantiated. I'm able to rack up over 1gb in memory for a single page and over 2.4gb in GPU memory usage by opening and closing modals that contain a mapbox. Is there any progress or potential fix for this right now? |
@iamanvesh How are you profiling the memory usage? I'm asking because I'm unable to reproduce on my end.
replacing You can see a clear spike when the first map loads, it then plateaus and drops off once the final map is unmounted. I used There could be something in your style or the interactions that you perform that causes a leak, we'll need that information inorder to debug. The only leak vector I could find through blind digging was the one in (#9337) around event handlers. If the style is sensitive information and not sharable publicly, you could reach out to mapbox support with that information. |
I was initially doing it manually with & without (using activity monitor) web inspector. I followed the same procedure that you've mentioned above and here are my observations.
|
Yes, but it seems like that the ~100M is also reused when a new map is initialized, otherwise you'd see memory usage keep on growing. Heap snapshots in both Safari and Chrome aren't showing any JS objects being retained as far as I can tell. Setting |
@arindam1993 I did try to run I've shared the style URL with the support team, were you able to find any issues with the style, if any? |
@iamanvesh , I've received the style URL, I'm the process of debugging with it. I don't see any possible memory leaks caused by the style itself. Chrome and Safari Dev tools don't seem to be showing anything different compared to regular mapbox streets. To answer definitively where this is coming from, I'm going to run profiling on debug builds of WebKit. This is somewhat slow and time consuming but I'll post my finding's here when I have something. |
@arindam1993 Is there any update on this issue? |
To everyone still following this issue, we don't have any leads on why this is Safari specific, the one we worked around surrounding Transferrable objects in WebWorkers has been acknowledged and fixed by the WebKit team. But no further updates are available. |
@arindam1993 Any update on this one? I found exactly the same issue in one of our hybrid applications, and created the same testing setup as @iamanvesh, and then later came across this issue. I created a basic site that recreates our crash https://blissful-mcclintock-aa92d1.netlify.app/. Basically it just loads a map, starts a Running this page on device (I'm using iPhone6S+, iOS14.2) Safari will crash after 25 runs or so. Running this on desktop Safari it takes quite a long time (50 runs or so, depends on available RAM I suppose), but it does eventually crash, with memory increasing constantly. We also see This bug is a massive problem for us. We use mapbox in a suite of hybrid mobile data collection apps which regularly create new maps as the user is entering data. To have it crash every ~20th time for the user is unacceptable. So we're actively looking into solutions and would be glad to assist in any investigation, even if you have a lead/hunch that you'd like looked at. Edit: Mildly interesting point to add, I just updated my reproduction site (see link above) to let you choose between running with a vector or a raster layer. With a raster (satellite-v9) layer, the crash takes much longer to happen - about ~120 runs on my iPhone6S compared to ~20 for the vector layer. |
Still experiencing the same problem 👍🏻 |
Any pointers to solve this on MapBox 3+? Memory keeps growing after .remove() |
@stepankuzmin @mourner Hey, is there any work planned for this issue? I can see that even with most recent mapbox v3.2.0-beta.1 it's kept alive in memory after mounting and re-mounting it few times with proper clean-up (map.remove() and DOM removal, via React to be exact). https://codesandbox.io/p/sandbox/mapbox-leak-zr336q?file=%2Findex.js In this sandbox it's vanilla JS, simply removing map and then adding it back again. After a few retries it's clearly visible that Map object is not garbage collected and it's piling up in memory Heap snapshot. :< |
Is this still relevant? |
While #8771 fixed the memory issue while using the map for prolonged period of time, we found that the memory used by the map is not being garbage collected when it un-mounts from the DOM. Please find attached the screenshots of the memory usage (react app). To test this behavior in isolation I've created a simple app which has only two pages, one of which loads a map onto the DOM and the other just has some text. Please use a resource intensive style URL (which has at least 4-5 layers and >300-500 features) for testing this scenario. Our dataset has >100K features spread across the USA.
Initial load of the app (Map has not been mounted yet):
Peak memory usage of the map (after panning/zooming around multiple times):
~15 seconds after the map unmounts:
When the map unmounts after repeating these steps 4 times:
mapbox-gl-js version: 1.6.0
browser: Predominantly on Safari but Chrome retains some memory too.
Steps to Trigger Behavior
Link to Demonstration
Without react: https://jsbin.com/zimigow/edit
With react: https://github.com/iamanvesh/mapbox-memory-leak-sample
Expected Behavior
The memory usage should come down to what is observed on the initial page load.
Actual Behavior
The memory usage stays at around ~500mb even after waiting for ~30-60 seconds.
The text was updated successfully, but these errors were encountered: