mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 20:56:09 +03:00
Merge pull request #1832 from JoFrMueller/pr-1721
Clear viewer and navigator listeners and nodes to avoid memory leaks
This commit is contained in:
commit
df850c62e8
@ -396,6 +396,20 @@ $.extend( $.Button.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.
|
||||
this.element.disabled = false;
|
||||
$.setElementOpacity( this.element, 1.0, true );
|
||||
this.notifyGroupEnter();
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.element.removeChild(this.imgRest);
|
||||
this.imgRest = null;
|
||||
this.element.removeChild(this.imgGroup);
|
||||
this.imgGroup = null;
|
||||
this.element.removeChild(this.imgHover);
|
||||
this.imgHover = null;
|
||||
this.element.removeChild(this.imgDown);
|
||||
this.imgDown = null;
|
||||
this.removeAllHandlers();
|
||||
this.tracker.destroy();
|
||||
this.element = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -129,6 +129,16 @@ $.ButtonGroup.prototype = {
|
||||
*/
|
||||
emulateExit: function() {
|
||||
this.tracker.exitHandler( { eventSource: this.tracker } );
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
while (this.buttons.length) {
|
||||
var button = this.buttons.pop();
|
||||
this.element.removeChild(button.element);
|
||||
button.destroy();
|
||||
}
|
||||
this.tracker.destroy();
|
||||
this.element = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -406,6 +406,10 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /*
|
||||
return $.Viewer.prototype.addTiledImage.apply(this, [optionsClone]);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
return $.Viewer.prototype.destroy.apply(this);
|
||||
},
|
||||
|
||||
// private
|
||||
_getMatchingItem: function(theirItem) {
|
||||
var count = this.world.getItemCount();
|
||||
|
@ -765,8 +765,23 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
this.drawer.destroy();
|
||||
}
|
||||
|
||||
if ( this.navigator ) {
|
||||
this.navigator.destroy();
|
||||
THIS[ this.navigator.hash ] = null;
|
||||
delete THIS[ this.navigator.hash ];
|
||||
this.navigator = null;
|
||||
}
|
||||
|
||||
this.removeAllHandlers();
|
||||
|
||||
if (this.buttons) {
|
||||
this.buttons.destroy();
|
||||
}
|
||||
|
||||
if (this.paging) {
|
||||
this.paging.destroy();
|
||||
}
|
||||
|
||||
// Go through top element (passed to us) and remove all children
|
||||
// Use removeChild to make sure it handles SVG or any non-html
|
||||
// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
|
||||
@ -776,6 +791,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
}
|
||||
}
|
||||
|
||||
this.container.onsubmit = null;
|
||||
this.clearControls();
|
||||
|
||||
// destroy the mouse trackers
|
||||
if (this.innerTracker){
|
||||
this.innerTracker.destroy();
|
||||
@ -3261,7 +3279,7 @@ function updateOnce( viewer ) {
|
||||
|
||||
//viewer.profiler.beginUpdate();
|
||||
|
||||
if (viewer._opening) {
|
||||
if (viewer._opening || !THIS[viewer.hash]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user