From 8e3856b4ac0d890b5f8acd8d250388c9a41149b5 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Mon, 26 Mar 2007 00:50:31 +0000 Subject: [PATCH] Commit small change to destroy events objects when destroying objects with events. This removes a number of minor memory leaks with creating/destroying popups, layers, features, and markers. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2894 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Feature.js | 4 ++++ lib/OpenLayers/Layer.js | 2 ++ lib/OpenLayers/Marker.js | 5 ++++- lib/OpenLayers/Popup.js | 4 +++- tests/test_Events.html | 3 ++- 5 files changed, 15 insertions(+), 3 deletions(-) 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"); }