Merge pull request #1832 from JoFrMueller/pr-1721

Clear viewer and navigator listeners and nodes to avoid memory leaks
This commit is contained in:
Ian Gilman 2020-06-10 09:41:43 -07:00 committed by GitHub
commit df850c62e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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