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

Fix terrain listener memory leak when removing Marker #4284

Merged
merged 2 commits into from
Jun 17, 2024
Merged

Fix terrain listener memory leak when removing Marker #4284

merged 2 commits into from
Jun 17, 2024

Conversation

rczobor
Copy link
Contributor

@rczobor rczobor commented Jun 17, 2024

A memory leak is caused when adding and removing markers. .on('terrain', this._update) event listener is added when Marker's addTo is called, but off call is missing from the remove method.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.68%. Comparing base (917fbb8) to head (5da6b3e).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4284      +/-   ##
==========================================
+ Coverage   87.42%   87.68%   +0.26%     
==========================================
  Files         242      242              
  Lines       33081    33082       +1     
  Branches     2170     2184      +14     
==========================================
+ Hits        28920    29009      +89     
+ Misses       3176     3075     -101     
- Partials      985      998      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TimMcCauley
Copy link

Thank you @rczobor this is a really nice find which will help us in our project, too.

Copy link
Collaborator

@HarelM HarelM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THANKS!

@HarelM
Copy link
Collaborator

HarelM commented Jun 17, 2024

Did you happen to check if there are other event that are causing a leak in this class?
I think there are in the geolocation control, but this control doesn't get added and removed often...

@HarelM HarelM merged commit cc8c714 into maplibre:main Jun 17, 2024
15 checks passed
@rczobor
Copy link
Contributor Author

rczobor commented Jun 17, 2024

Thanks!

We didn't notice any other events so far, only this one. We do use supercluster to render thousands of dynamic markers with click/drag event handlers on the map via react-nap-gl, and this one popped out. It can crash a tab in minutes when abused.
Screenshot 2024-06-14 at 13 20 11

@rczobor rczobor deleted the fix-terrain-listener-memory-leak branch June 17, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants