diff --git a/lib/OpenLayers/Feature.js b/lib/OpenLayers/Feature.js index 734fbe577f..f98c10c230 100644 --- a/lib/OpenLayers/Feature.js +++ b/lib/OpenLayers/Feature.js @@ -59,7 +59,11 @@ OpenLayers.Feature.prototype= { } } + if (this.events) { + this.events.destroy(); + } this.events = null; + this.layer = null; this.id = null; this.lonlat = null; diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index c632cb8110..c84f448365 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -154,6 +154,8 @@ OpenLayers.Layer.prototype = { this.name = null; this.div = null; this.options = null; + + this.events.destroy(); this.events = null; }, diff --git a/lib/OpenLayers/Marker.js b/lib/OpenLayers/Marker.js index 1338e9c124..100a28cdb3 100644 --- a/lib/OpenLayers/Marker.js +++ b/lib/OpenLayers/Marker.js @@ -47,7 +47,10 @@ OpenLayers.Marker.prototype = { destroy: function() { this.map = null; - + + this.events.destroy(); + this.events = null; + if (this.icon != null) { this.icon.destroy(); this.icon = null; diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index 7506e77b7e..f13f2680b8 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -117,9 +117,11 @@ OpenLayers.Popup.prototype = { destroy: function() { if (this.map != null) { this.map.removePopup(this); + this.map = null; } + this.events.destroy(); + this.events = null; this.div = null; - this.map = null; }, /** diff --git a/tests/test_Events.html b/tests/test_Events.html index 65c79241d3..2582942090 100644 --- a/tests/test_Events.html +++ b/tests/test_Events.html @@ -212,7 +212,8 @@ t.eq(OpenLayers.Event.observers.length, start + OpenLayers.Events.prototype.BROWSER_EVENTS.length + 1, "construction increases the number of event observers"); - events = events.destroy(); + events.destroy(); + events = null; t.eq(OpenLayers.Event.observers.length, start, "destruction restores the number of event observers"); }