diff --git a/src/imagetilesource.js b/src/imagetilesource.js index 375c65d6..da1c201b 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -195,6 +195,13 @@ } return context; }, + /** + * Destroys ImageTileSource + * @function + */ + destroy: function () { + this._freeupCanvasMemory(); + }, // private // @@ -258,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/tiledimage.js b/src/tiledimage.js index 347a5b3e..cc05cb57 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -326,6 +326,10 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag */ destroy: function() { this.reset(); + + if (this.source.destroy) { + this.source.destroy(); + } }, /** diff --git a/test/demo/memorycheck-with-simple-image.html b/test/demo/memorycheck-with-simple-image.html new file mode 100644 index 00000000..292c6994 --- /dev/null +++ b/test/demo/memorycheck-with-simple-image.html @@ -0,0 +1,55 @@ + + + + OpenSeadragon Memory Check With Simple Image Demo + + + + +
+ Simple demo page to monitor OpenSeadragon Memory Usage. +
+ + + + +
+ + +