mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Merge pull request #1789 from TakumaKira/master
Add freeupCanvasMemory method on Viewer.destroy method.
This commit is contained in:
commit
db85f77c88
@ -195,6 +195,13 @@
|
|||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Destroys ImageTileSource
|
||||||
|
* @function
|
||||||
|
*/
|
||||||
|
destroy: function () {
|
||||||
|
this._freeupCanvasMemory();
|
||||||
|
},
|
||||||
|
|
||||||
// private
|
// private
|
||||||
//
|
//
|
||||||
@ -258,7 +265,19 @@
|
|||||||
bigContext = smallContext;
|
bigContext = smallContext;
|
||||||
}
|
}
|
||||||
return levels;
|
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));
|
}(OpenSeadragon));
|
||||||
|
@ -326,6 +326,10 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
*/
|
*/
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
|
if (this.source.destroy) {
|
||||||
|
this.source.destroy();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
55
test/demo/memorycheck-with-simple-image.html
Normal file
55
test/demo/memorycheck-with-simple-image.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user