diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index 50c2548202..abfdf24f39 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -339,9 +339,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { */ setImgSrc: function(url) { var img = this.imgDiv; - img.style.visibility = 'hidden'; - img.style.opacity = 0; if (url) { + img.style.visibility = 'hidden'; + img.style.opacity = 0; // don't set crossOrigin if the url is a data URL if (this.crossOriginKeyword) { if (url.substr(0, 5) !== 'data:') { @@ -351,6 +351,13 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { } } img.src = url; + } else { + // Remove reference to the image, and leave it to the browser's + // caching and garbage collection. + this.imgDiv = null; + if (img.parentNode) { + img.parentNode.removeChild(img); + } } },