make a destroy method and a clear grid. preventing circular refrences and memory leaks

git-svn-id: http://svn.openlayers.org/trunk/openlayers@184 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-19 16:25:19 +00:00
parent 54f519a255
commit 20a13f43a6
2 changed files with 30 additions and 1 deletions

View File

@@ -73,6 +73,10 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
//first of all, clear out the main div
this.div.innerHTML = "";
//now clear out the old grid and start a new one
this.clearGrid();
this.grid = new Array();
var viewSize = this.map.getSize();
var bounds = this.map.getExtent();
var extent = this.map.getFullExtent();
@@ -96,7 +100,6 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
tileoffsety = Math.round(tileoffsety);
this.origin = new OpenLayers.Pixel(tileoffsetx,tileoffsety);
this.grid = new Array();
var startX = tileoffsetx;
var startLon = tileoffsetlon;
@@ -223,5 +226,23 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
}
}
return requestString;
},
/** go through and remove all tiles from the grid, calling
* destroy() on each of them to kill circular references
*
* @private
*/
clearGrid:function() {
while(grid.length > 0) {
var row = grid[0];
while(row.length > 0) {
var tile = row[0];
tile.destroy();
row.remove(tile);
}
grid.remove(row);
}
}
});

View File

@@ -42,6 +42,14 @@ OpenLayers.Tile.prototype = {
this.size = size;
}
},
/** nullify references to prevent circular references and memory leaks
*/
destroy:function() {
this.grid = null;
this.bounds = null;
this.size = null;
},
/**
*/