meekee
meekee

Reputation: 21

Erasing a layer from a leaflet map

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

Answers (2)

YaFred
YaFred

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

IvanSanchez
IvanSanchez

Reputation: 19059

Just remove the layer from the map (that will destroy all its HTMLElements) and make sure there are no Javascript variables referencing it. Your browser's garbage collector will do the rest.

Upvotes: 1

Related Questions