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

control.onRemove isn't called when map.remove() is called #6487

Closed
5 tasks done
callumacrae opened this issue Jan 22, 2019 · 1 comment · Fixed by #6488
Closed
5 tasks done

control.onRemove isn't called when map.remove() is called #6487

callumacrae opened this issue Jan 22, 2019 · 1 comment · Fixed by #6488

Comments

@callumacrae
Copy link

  • I've looked at the documentation to make sure the behavior is documented and expected
  • I'm sure this is a Leaflet code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • I've searched through the issues to make sure it's not yet reported

The issue

I am currently trying to track down a memory leak in my application. One potential place I've found is that control.onRemove isn't called when map.remove() is called.

https://leafletjs.com/reference-1.4.0.html#control

I'm doing stuff in control.onAdd that needs tearing down when the map is removed, but control.onRemove isn't called when map.remove() is called.

In order to help prevent memory leaks, it would be useful if control.onRemove were called when the map is removed.

Environment

  • Leaflet version: 1.4.0
  • Browser (with version): all
  • OS/Platform (with version): all

Minimal example reproducing the issue

https://jsbin.com/qofetabumu/1/edit?html,js,output warning: resource intensive

the memory usage of the page goes up by about 50 MB a second, and because it's being used by an event listener that isn't removed, it can't be garbage collected.

this is a totally unrealistic example but my actual case is super complicated and i'm not sure how to simplify it

  • this example is as simple as possible
  • this example does not rely on any third party code

I'd be willing to have a crack at fixing this but would need pointing in the right direction as I haven't contributed to leaflet before :)

@IvanSanchez
Copy link
Member

That's a good point - destroying the map removes the control corners (and therefore the DOM elements from any controls) from the DOM, but doesn't tear down the controls. Noticing that the teardown code from the controls is not running is a nice catch!!

@callumacrae Please see #6488 - it should do a better cleanup of the controls, but it needs testing - could you please have a look at that?

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 a pull request may close this issue.

2 participants