mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-16 14:53:14 +03:00
Fix memory leak while destroying the viewer.
This commit is contained in:
parent
e4800a9455
commit
764fa3e34a
@ -302,7 +302,22 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
|
|||||||
*/
|
*/
|
||||||
canRotate: function() {
|
canRotate: function() {
|
||||||
return this.useCanvas;
|
return this.useCanvas;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the drawer (unload current loaded tiles)
|
||||||
|
*/
|
||||||
|
destroy: function() {
|
||||||
|
|
||||||
|
//unload current loaded tiles (=empty TILE_CACHE)
|
||||||
|
for (var i=0; i<this.tilesLoaded.length; ++i) {
|
||||||
|
this.tilesLoaded[i].unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
//force unloading of current canvas (1x1 will be gc later, trick not necessary needed)
|
||||||
|
this.canvas.width = 1;
|
||||||
|
this.canvas.height = 1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,6 +252,9 @@
|
|||||||
destroy: function () {
|
destroy: function () {
|
||||||
stopTracking( this );
|
stopTracking( this );
|
||||||
this.element = null;
|
this.element = null;
|
||||||
|
|
||||||
|
THIS[ this.hash ] = null;
|
||||||
|
delete THIS[ this.hash ];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -542,6 +542,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
this.drawersContainer.innerHTML = "";
|
this.drawersContainer.innerHTML = "";
|
||||||
this.overlaysContainer.innerHTML = "";
|
this.overlaysContainer.innerHTML = "";
|
||||||
|
|
||||||
|
if (this.drawer) {
|
||||||
|
this.drawer.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
this.source = null;
|
this.source = null;
|
||||||
this.drawer = null;
|
this.drawer = null;
|
||||||
this.drawers = [];
|
this.drawers = [];
|
||||||
@ -596,7 +600,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
if (this.outerTracker){
|
if (this.outerTracker){
|
||||||
this.outerTracker.destroy();
|
this.outerTracker.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
THIS[ this.hash ] = null;
|
||||||
|
delete THIS[ this.hash ];
|
||||||
|
|
||||||
// clear all our references to dom objects
|
// clear all our references to dom objects
|
||||||
this.canvas = null;
|
this.canvas = null;
|
||||||
this.keyboardCommandArea = null;
|
this.keyboardCommandArea = null;
|
||||||
|
71
test/demo/memory_check.html
Normal file
71
test/demo/memory_check.html
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>OpenSeadragon Memory Check 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>
|
||||||
|
<button onclick="createViewer()">Create</button>
|
||||||
|
<button onclick="destroyViewer()">Destroy</button>
|
||||||
|
|
||||||
|
<div id="contentDiv" class="openseadragon1"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var _viewer;
|
||||||
|
|
||||||
|
var generateUniqueHash = (function() {
|
||||||
|
var counter = 0;
|
||||||
|
return function() {
|
||||||
|
return "seadragon_"+(counter++);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
function createViewer() {
|
||||||
|
if (_viewer) {
|
||||||
|
destroyViewer();
|
||||||
|
}
|
||||||
|
|
||||||
|
_viewer = OpenSeadragon({
|
||||||
|
element: document.getElementById("contentDiv"),
|
||||||
|
showNavigationControl: false,
|
||||||
|
springStiffness: 20,
|
||||||
|
animationTime : 1.5,
|
||||||
|
visibilityRatio: 1,
|
||||||
|
hash: "hello",
|
||||||
|
tileSources: {
|
||||||
|
Image: {
|
||||||
|
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
|
||||||
|
Url: 'http://cdn.photosynth.net/ps2/92fe5de9-dffa-4315-9095-082da8b90642/packet/undistorted/img0014/',
|
||||||
|
Format: "jpg",
|
||||||
|
Overlap: 1,
|
||||||
|
TileSize: 510,
|
||||||
|
Size: {
|
||||||
|
Width: 4592,
|
||||||
|
Height: 3448
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyViewer() {
|
||||||
|
if (_viewer) {
|
||||||
|
_viewer.destroy();
|
||||||
|
}
|
||||||
|
_viewer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user