From 81b038926c89b39b2a3220a639c118987d4eda15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Thu, 4 Jun 2015 16:20:13 +0200 Subject: [PATCH] Cleaning up map layers when map.remove() is run --- debug/tests/detached-dom-memory-leak.html | 56 +++++++++++++++++++++++ src/map/Map.js | 4 ++ 2 files changed, 60 insertions(+) create mode 100644 debug/tests/detached-dom-memory-leak.html diff --git a/debug/tests/detached-dom-memory-leak.html b/debug/tests/detached-dom-memory-leak.html new file mode 100644 index 00000000..220cfe11 --- /dev/null +++ b/debug/tests/detached-dom-memory-leak.html @@ -0,0 +1,56 @@ + + + + Leaflet debug page + + + + + + + + + +This page will destroy and recreate a map div lots of times. Developer tools shall not display a memory leak. + +
+ + + +
+ + + \ No newline at end of file diff --git a/src/map/Map.js b/src/map/Map.js index f0c0c162..8dca0f26 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -272,6 +272,10 @@ L.Map = L.Evented.extend({ this.fire('unload'); } + for (var i in this._layers) { + this._layers[i].remove(); + } + return this; },