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

Memory leak on map.remove() #4811

Closed
elo58 opened this issue Oct 8, 2024 · 5 comments · Fixed by #4824
Closed

Memory leak on map.remove() #4811

elo58 opened this issue Oct 8, 2024 · 5 comments · Fixed by #4824
Labels
bug Something isn't working good first issue Good for newcomers PR is more than welcomed Extra attention is needed

Comments

@elo58
Copy link

elo58 commented Oct 8, 2024

hello,

I have a website where several pages contain a maplibre map. It's a SPA so maplibre-gl.js is not unloaded/reloaded for each map. Maps are created and destroyed over the navigation.
I have issues with memory consumption which increase each time i create and then destroy a map.

My work is based on maplibre 4.1 but i have also tested with maplibre 4.7.1 and the issue is the same (may be a little better with 4.7.1)

maplibre-gl-js version: 4.7.1

browser: Chrome 128 / linux

Steps to Trigger Behavior

  1. map = new maplibregl.Map({ ... })
  2. map.remove()
  3. monitor memory consumption

Link to Demonstration

I have wrote a sample code to reproduce my problem :
https://output.jsbin.com/vumugiroma
Each time you press 'space' key you create or destroy a map.
The total used memory increase at each time (Check with Chrome task manager or memory in Devtools)

Expected Behavior

Don't increase memory consumption after several creation and destruction of maps.

Actual Behavior

Some objects are not released

@HarelM
Copy link
Collaborator

HarelM commented Oct 8, 2024

Thanks for taking the time to report this issue!
Feel free to investigate further and open a PR to fix this.
There is a lot of cleaning up code in map.remove method, but there might be places that were not handled properly.

@HarelM HarelM added bug Something isn't working good first issue Good for newcomers PR is more than welcomed Extra attention is needed labels Oct 8, 2024
@HarelM
Copy link
Collaborator

HarelM commented Oct 8, 2024

There's also this report, which has a root cause investigated already:

@kamil-sienkiewicz-asi
Copy link
Contributor

@HarelM Hey, I've already fixed map.remove() memory leak in mapbox, maybe it's somewhat similar/in similar place?

mapbox/mapbox-gl-js#13110
mapbox/mapbox-gl-js#13116

Not aware of maplibre code yet, so I'm just guessing and throwing ideas.
Might take a look at it at some point.

@HarelM
Copy link
Collaborator

HarelM commented Oct 10, 2024

I can't look at the linked code since I don't want to infringe copyright laws, but you are more than welcome to tackle the memory leak in this lib.

@HarelM
Copy link
Collaborator

HarelM commented Oct 13, 2024

I've opened a PR to fix the relevant memory leak I observed using chrome devtools.

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

Successfully merging a pull request may close this issue.

3 participants