From a1522246a6aec9c9f842917d30b658ad62a0edc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 17 Dec 2007 09:03:01 +0000 Subject: [PATCH] Subclasses of markers layer should destroy, then clear their list of markers. Thanks crschmidt for the review. (closes #1123) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5465 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/GeoRSS.js | 7 ++++++- lib/OpenLayers/Layer/Text.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Layer/GeoRSS.js b/lib/OpenLayers/Layer/GeoRSS.js index abf968b6b0..0c9061e7d1 100644 --- a/lib/OpenLayers/Layer/GeoRSS.js +++ b/lib/OpenLayers/Layer/GeoRSS.js @@ -75,9 +75,14 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, { * Method: destroy */ destroy: function() { + // Warning: Layer.Markers.destroy() must be called prior to calling + // clearFeatures() here, otherwise we leak memory. Indeed, if + // Layer.Markers.destroy() is called after clearFeatures(), it won't be + // able to remove the marker image elements from the layer's div since + // the markers will have been destroyed by clearFeatures(). + OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); this.clearFeatures(); this.features = null; - OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); }, /** diff --git a/lib/OpenLayers/Layer/Text.js b/lib/OpenLayers/Layer/Text.js index 9141dc103d..703b505c06 100644 --- a/lib/OpenLayers/Layer/Text.js +++ b/lib/OpenLayers/Layer/Text.js @@ -86,9 +86,14 @@ OpenLayers.Layer.Text = OpenLayers.Class(OpenLayers.Layer.Markers, { * APIMethod: destroy */ destroy: function() { + // Warning: Layer.Markers.destroy() must be called prior to calling + // clearFeatures() here, otherwise we leak memory. Indeed, if + // Layer.Markers.destroy() is called after clearFeatures(), it won't be + // able to remove the marker image elements from the layer's div since + // the markers will have been destroyed by clearFeatures(). + OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); this.clearFeatures(); this.features = null; - OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); },