From 798e49e4b26ad0191a9e95aaea013a65b9f73e73 Mon Sep 17 00:00:00 2001 From: Takuma Kira Date: Wed, 18 Mar 2020 14:37:45 +0900 Subject: [PATCH] - Add freeupCanvasMemory method on Viewer.destroy method. --- src/imagetilesource.js | 12 ++++++++++++ src/viewer.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/imagetilesource.js b/src/imagetilesource.js index 375c65d6..d8d2a6d9 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -195,6 +195,18 @@ } 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). + * @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; + } + }, // private // diff --git a/src/viewer.js b/src/viewer.js index 20e06186..b13483dc 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -742,6 +742,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } + if (this.source.freeupCanvasMemory) { + this.source.freeupCanvasMemory(); + } + this.close(); this.clearOverlays();