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:
@@ -73,6 +73,10 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
//first of all, clear out the main div
|
//first of all, clear out the main div
|
||||||
this.div.innerHTML = "";
|
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 viewSize = this.map.getSize();
|
||||||
var bounds = this.map.getExtent();
|
var bounds = this.map.getExtent();
|
||||||
var extent = this.map.getFullExtent();
|
var extent = this.map.getFullExtent();
|
||||||
@@ -96,7 +100,6 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
tileoffsety = Math.round(tileoffsety);
|
tileoffsety = Math.round(tileoffsety);
|
||||||
|
|
||||||
this.origin = new OpenLayers.Pixel(tileoffsetx,tileoffsety);
|
this.origin = new OpenLayers.Pixel(tileoffsetx,tileoffsety);
|
||||||
this.grid = new Array();
|
|
||||||
|
|
||||||
var startX = tileoffsetx;
|
var startX = tileoffsetx;
|
||||||
var startLon = tileoffsetlon;
|
var startLon = tileoffsetlon;
|
||||||
@@ -223,5 +226,23 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return requestString;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ OpenLayers.Tile.prototype = {
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** nullify references to prevent circular references and memory leaks
|
||||||
|
*/
|
||||||
|
destroy:function() {
|
||||||
|
this.grid = null;
|
||||||
|
this.bounds = null;
|
||||||
|
this.size = null;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user