From fd514e8435a24eb68f980285ff75e418ddf71bb1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 24 Oct 2009 04:21:02 +0000 Subject: [PATCH] fixed memory leak in Marker.js. With manual test. p=rcoup, r=me (closes #2258) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9754 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Marker.js | 11 +++-- tests/manual/memory/Marker-2258.html | 60 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 tests/manual/memory/Marker-2258.html diff --git a/lib/OpenLayers/Marker.js b/lib/OpenLayers/Marker.js index 3e0845eb5e..88482d953e 100644 --- a/lib/OpenLayers/Marker.js +++ b/lib/OpenLayers/Marker.js @@ -78,7 +78,6 @@ OpenLayers.Marker = OpenLayers.Class({ this.icon.offset = newIcon.offset; this.icon.calculateOffset = newIcon.calculateOffset; } - this.events = new OpenLayers.Events(this, this.icon.imageDiv, null); }, /** @@ -94,9 +93,6 @@ OpenLayers.Marker = OpenLayers.Class({ this.map = null; - this.events.destroy(); - this.events = null; - if (this.icon != null) { this.icon.destroy(); this.icon = null; @@ -115,6 +111,9 @@ OpenLayers.Marker = OpenLayers.Class({ * location passed-in */ draw: function(px) { + if (!this.events) { + this.events = new OpenLayers.Events(this, this.icon.imageDiv, null); + } return this.icon.draw(px); }, @@ -126,6 +125,10 @@ OpenLayers.Marker = OpenLayers.Class({ if (this.icon != null) { this.icon.erase(); } + if (this.events) { + this.events.destroy(); + this.events = null; + } }, /** diff --git a/tests/manual/memory/Marker-2258.html b/tests/manual/memory/Marker-2258.html new file mode 100644 index 0000000000..b2d8a37b09 --- /dev/null +++ b/tests/manual/memory/Marker-2258.html @@ -0,0 +1,60 @@ + + + Memory Test - Layer.Markers / Marker + + + + + + + +

Memory Test - Layer.Markers / Marker

+

+    
+

+ This test is a memory leak test for usage of Layer.Markers / Marker. +

+

+ Run this test in IE6/7 with JavaScript Memory Leak Detector v2 + and watch it identify a leak unless this is fixed. +

+ +