Merge pull request #1789 from TakumaKira/master

Add freeupCanvasMemory method on Viewer.destroy method.
This commit is contained in:
Ian Gilman 2020-04-30 09:33:56 -07:00 committed by GitHub
commit db85f77c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 1 deletions

View File

@ -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));

View File

@ -326,6 +326,10 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
*/
destroy: function() {
this.reset();
if (this.source.destroy) {
this.source.destroy();
}
},
/**

View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<title>OpenSeadragon Memory Check With Simple Image Demo</title>
<script type="text/javascript" src='../../build/openseadragon/openseadragon.js'></script>
<style type="text/css">
.openseadragon1 {
width: 800px;
height: 600px;
}
</style>
</head>
<body>
<div>
Simple demo page to monitor OpenSeadragon Memory Usage.
</div>
<!-- To get "Total canvas memory use exceeds the maximum limit" warning and then "null is not an object (evaluating 'smallContext.drawImage')" error,
disable _freeupCanvasMemory method in ImageTileSource,
then click Create button below 12 times on "iPad Air (3rd generation) -- 13.3" Simulator on Mac with Web Inspector by Safari. -->
<button onclick="createViewer()">Create</button>
<button onclick="destroyViewer()">Destroy</button>
<div id="contentDiv" class="openseadragon1"></div>
<script type="text/javascript">
var _viewer;
function createViewer() {
if ( _viewer ) {
destroyViewer();
}
_viewer = OpenSeadragon({
element: document.getElementById("contentDiv"),
showNavigationControl: false,
prefixUrl: "../../build/openseadragon/images/",
tileSources: {
type: "image",
url: "../data/CCyan.png"
}
});
}
function destroyViewer() {
if ( _viewer ) {
_viewer.destroy();
}
_viewer = null;
}
</script>
</body>
</html>