Fix a memory leak in Tile.Image when using AlphaHack. r=crschmidt (closes #1848)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8407 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -109,10 +109,14 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
destroy: function() {
|
destroy: function() {
|
||||||
if (this.imgDiv != null) {
|
if (this.imgDiv != null) {
|
||||||
if (this.layerAlphaHack) {
|
if (this.layerAlphaHack) {
|
||||||
|
// unregister the "load" handler
|
||||||
OpenLayers.Event.stopObservingElement(this.imgDiv.childNodes[0].id);
|
OpenLayers.Event.stopObservingElement(this.imgDiv.childNodes[0].id);
|
||||||
} else {
|
|
||||||
OpenLayers.Event.stopObservingElement(this.imgDiv.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unregister the "load" and "error" handlers. Only the "error" handler if
|
||||||
|
// this.layerAlphaHack is true.
|
||||||
|
OpenLayers.Event.stopObservingElement(this.imgDiv.id);
|
||||||
|
|
||||||
if (this.imgDiv.parentNode == this.frame) {
|
if (this.imgDiv.parentNode == this.frame) {
|
||||||
this.frame.removeChild(this.imgDiv);
|
this.frame.removeChild(this.imgDiv);
|
||||||
this.imgDiv.map = null;
|
this.imgDiv.map = null;
|
||||||
|
|||||||
@@ -25,6 +25,43 @@
|
|||||||
t.ok( tile.size.equals(size), "tile.size is set correctly");
|
t.ok( tile.size.equals(size), "tile.size is set correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_destroy_observers(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
var position = new OpenLayers.Pixel(20,30);
|
||||||
|
var bounds = new OpenLayers.Bounds(1,2,3,4);
|
||||||
|
var size = new OpenLayers.Size(5,6);
|
||||||
|
|
||||||
|
// with alpha hack
|
||||||
|
var withAlpha = new OpenLayers.Tile.Image(layer, position, bounds, null, size);
|
||||||
|
withAlpha.layerAlphaHack = true;
|
||||||
|
|
||||||
|
withAlpha.draw();
|
||||||
|
var cacheID = withAlpha.imgDiv._eventCacheID;
|
||||||
|
withAlpha.destroy();
|
||||||
|
|
||||||
|
t.eq(OpenLayers.Event.observers[cacheID], undefined,
|
||||||
|
"With alpha hack: imgDiv observers are cleared in destroy");
|
||||||
|
|
||||||
|
// without alpha hack
|
||||||
|
var withoutAlpha = new OpenLayers.Tile.Image(layer, position, bounds, null, size);
|
||||||
|
withoutAlpha.layerAlphaHack = false;
|
||||||
|
|
||||||
|
withoutAlpha.draw();
|
||||||
|
var cacheID = withoutAlpha.imgDiv._eventCacheID;
|
||||||
|
withoutAlpha.destroy();
|
||||||
|
|
||||||
|
t.eq(OpenLayers.Event.observers[cacheID], undefined,
|
||||||
|
"Without alpha hack: imgDiv observers are cleared in destroy");
|
||||||
|
|
||||||
|
map.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
function test_Tile_Image_clone (t) {
|
function test_Tile_Image_clone (t) {
|
||||||
t.plan( 9 );
|
t.plan( 9 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user