diff --git a/src/imagetilesource.js b/src/imagetilesource.js index d8d2a6d9..da1c201b 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -196,16 +196,11 @@ return context; }, /** - * 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). + * Destroys ImageTileSource * @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; - } + destroy: function () { + this._freeupCanvasMemory(); }, // private @@ -270,7 +265,19 @@ 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/viewer.js b/src/viewer.js index b13483dc..93217150 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -742,8 +742,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } - if (this.source.freeupCanvasMemory) { - this.source.freeupCanvasMemory(); + //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.close(); diff --git a/test/demo/memorycheck-with-simple-image.html b/test/demo/memorycheck-with-simple-image.html index fbcea944..c676b062 100644 --- a/test/demo/memorycheck-with-simple-image.html +++ b/test/demo/memorycheck-with-simple-image.html @@ -16,6 +16,9 @@
Simple demo page to monitor OpenSeadragon Memory Usage.
+ @@ -24,13 +27,6 @@ var _viewer; - var generateUniqueHash = (function() { - var counter = 0; - return function() { - return "openseadragon_" + (counter++); - }; - })(); - function createViewer() { if ( _viewer ) { destroyViewer(); @@ -39,8 +35,6 @@ _viewer = OpenSeadragon({ element: document.getElementById("contentDiv"), showNavigationControl: false, - prefixUrl: "../../build/openseadragon/images/", - hash: generateUniqueHash(), //this is only needed if you want to instantiate more than one viewer at a time. tileSources: { type: "image", url: "../data/CCyan.png"