Reputation: 21
With leaflet removelayer, I still can use addlayer to put it back, they just work like an on off switch. Is there a way to really destroy the layer and free up memory. Thanks.
Upvotes: 2
Views: 904
Reputation: 10008
It depends on the scope of your variable (the one in the removelayer call). If it is global, you can set it to null. If not, you don't need to do anything.
See How to free up the memory in JavaScript
Upvotes: 1
Reputation: 19059
Just remove the layer from the map (that will destroy all its HTMLElement
s) and make sure there are no Javascript variables referencing it. Your browser's garbage collector will do the rest.
Upvotes: 1