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

map.remove() doesn’t clean up data inside Worker class -> memory leak #3733

Closed
pasieronen opened this issue Feb 22, 2024 · 0 comments · Fixed by #3734
Closed

map.remove() doesn’t clean up data inside Worker class -> memory leak #3733

pasieronen opened this issue Feb 22, 2024 · 0 comments · Fixed by #3734
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed

Comments

@pasieronen
Copy link
Contributor

maplibre-gl-js version: 4.0.2

browser: Chrome 122.0.6261.57

DEMO: https://jsbin.com/moburomadu/edit?html,output

The Worker class has several caches (layerIndexes, availableImages, workerSources, demWorkerSources) that use mapId as a key. It looks like they won’t get cleaned up by map.remove() (or anything else except terminating the worker), and thus leak memory if you remove and create new maps often (e.g. inside a single-page app).

You can observe this in Chrome DevTools "Memory" tab (memory usage for the worker keeps growing), or directly by looking at the data (select the worker in "Console" tab and print Object.keys(worker.layerIndexes)).

I guess the way to fix this would be to send a removeMap message to the Worker? I can do a PR for that next...

pasieronen added a commit to pasieronen/maplibre-gl-js that referenced this issue Feb 22, 2024
@HarelM HarelM added bug Something isn't working PR is more than welcomed Extra attention is needed labels Feb 26, 2024
pasieronen added a commit to pasieronen/maplibre-gl-js that referenced this issue Feb 26, 2024
HarelM pushed a commit that referenced this issue Feb 27, 2024
* Remove data inside Worker when map is remove (#3733)

* Add tests

* Update changelog

* Simplify test assertion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants