diff --git a/src/imagetilesource.js b/src/imagetilesource.js index da1c201b..d8d2a6d9 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -196,11 +196,16 @@ return context; }, /** - * Destroys ImageTileSource + * Free up canvas memory + * (iOS 12 or higher on 2GB RAM device has only 224MB canvas memory, + * and Safari keeps canvas until its height and width will be set to 0). * @function */ - destroy: function () { - this._freeupCanvasMemory(); + freeupCanvasMemory: function () { + for (var i = 0; i < this.levels.length; i++) { + this.levels[i].context2D.canvas.height = 0; + this.levels[i].context2D.canvas.width = 0; + } }, // private @@ -265,19 +270,7 @@ bigContext = smallContext; } return levels; - }, - /** - * Free up canvas memory - * (iOS 12 or higher on 2GB RAM device has only 224MB canvas memory, - * and Safari keeps canvas until its height and width will be set to 0). - * @function - */ - _freeupCanvasMemory: function () { - for (var i = 0; i < this.levels.length; i++) { - this.levels[i].context2D.canvas.height = 0; - this.levels[i].context2D.canvas.width = 0; - } - }, + } }); }(OpenSeadragon)); diff --git a/src/tilesource.js b/src/tilesource.js index d85f5ee6..5ce151eb 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -615,7 +615,17 @@ $.TileSource.prototype = { y >= 0 && x < numTiles.x && y < numTiles.y; - } + }, + + /** + * Destroys TileSource + * @function + */ + destroy: function () { + if ( this.freeupCanvasMemory ) { + this.freeupCanvasMemory(); + } + }, }; diff --git a/src/viewer.js b/src/viewer.js index 93217150..4653df98 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -742,10 +742,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } - //TODO: implement destroy and _freeupCanvasMemory method for all child classes of TileSource, then remove if statement wrap below. - if (this.source.destroy) { - this.source.destroy(); - } + this.source.destroy(); this.close(); diff --git a/test/demo/memorycheck-with-simple-image.html b/test/demo/memorycheck-with-simple-image.html index c676b062..292c6994 100644 --- a/test/demo/memorycheck-with-simple-image.html +++ b/test/demo/memorycheck-with-simple-image.html @@ -35,6 +35,7 @@ _viewer = OpenSeadragon({ element: document.getElementById("contentDiv"), showNavigationControl: false, + prefixUrl: "../../build/openseadragon/images/", tileSources: { type: "image", url: "../data/CCyan.png"