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:
Frédéric Junod
2008-11-21 15:04:52 +00:00
parent d64cec2db2
commit d695c29269
2 changed files with 44 additions and 3 deletions

View File

@@ -109,10 +109,14 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
destroy: function() {
if (this.imgDiv != null) {
if (this.layerAlphaHack) {
// unregister the "load" handler
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) {
this.frame.removeChild(this.imgDiv);
this.imgDiv.map = null;

View File

@@ -24,7 +24,44 @@
t.eq( tile.url, url, "tile.url 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) {
t.plan( 9 );