Memory leak fixes (#2387)

* Clean up listeners

* Fix uses of 'destroy' instead of 'destroyed'
This commit is contained in:
Andrew Henry 2019-04-26 10:34:24 -07:00 committed by Deep Tailor
parent d2e2d55caf
commit 844280eaa5
6 changed files with 32 additions and 13 deletions

View File

@ -45,22 +45,27 @@ define([
view: function (domainObject) {
let $rootScope = openmct.$injector.get('$rootScope');
let templateLinker = openmct.$injector.get('templateLinker');
let scope = $rootScope.$new();
let scope = $rootScope.$new(true);
let legacyObject = convertToLegacyObject(domainObject);
let isDestroyed = false;
let unlistenToStatus;
let element;
scope.domainObject = legacyObject;
scope.model = legacyObject.getModel();
let child;
let parent;
return {
show: function (container) {
parent = container;
child = document.createElement('div');
parent.appendChild(child);
let statusCapability = legacyObject.getCapability('status');
unlistenToStatus = statusCapability.listen((newStatus) => {
container.classList.remove('s-status-timeconductor-unsynced');
child.classList.remove('s-status-timeconductor-unsynced');
if (newStatus.includes('timeconductor-unsynced')) {
container.classList.add('s-status-timeconductor-unsynced');
child.classList.add('s-status-timeconductor-unsynced');
}
});
@ -84,12 +89,13 @@ define([
uses.forEach(function (key, i) {
scope[key] = results[i];
});
element = openmct.$angular.element(child);
templateLinker.link(
scope,
openmct.$angular.element(container),
element,
legacyView
);
container.classList.add('u-contents');
child.classList.add('u-contents');
}
if (promises.length) {
@ -103,7 +109,11 @@ define([
}
},
destroy: function () {
element.off();
element.remove();
scope.$destroy();
element = null;
scope = null;
unlistenToStatus();
}
}

View File

@ -41,15 +41,18 @@ define([
let domainObject = selection[0][0].context.item;
let $rootScope = openmct.$injector.get('$rootScope');
let templateLinker = openmct.$injector.get('templateLinker');
let scope = $rootScope.$new();
let scope = $rootScope.$new(true);
let legacyObject = convertToLegacyObject(domainObject);
let isDestroyed = false;
let element;
scope.domainObject = legacyObject;
scope.model = legacyObject.getModel();
return {
show: function (container) {
let child = document.createElement('div');
container.appendChild(child);
// TODO: implement "gestures" support ?
let uses = representation.uses || [];
let promises = [];
@ -70,9 +73,10 @@ define([
uses.forEach(function (key, i) {
scope[key] = results[i];
});
element = openmct.$angular.element(child)
templateLinker.link(
scope,
openmct.$angular.element(container),
element,
representation
);
container.style.height = '100%';
@ -89,7 +93,11 @@ define([
}
},
destroy: function () {
element.off();
element.remove();
scope.$destroy();
element = null;
scope = null;
}
}
}

View File

@ -239,7 +239,7 @@ define([
this.filteredRows.destroy();
Object.keys(this.subscriptions).forEach(this.unsubscribe, this);
this.openmct.time.off('bounds', this.refreshData);
this.openmct.time.on('timeSystem', this.refreshData);
this.openmct.time.off('timeSystem', this.refreshData);
if (this.filterObserver) {
this.filterObserver();
}

View File

@ -70,17 +70,18 @@
this.domainObject = newObject;
});
this.$once('hook:destroyed', removeListener);
if (this.openmct.composition.get(this.node.object)) {
this.hasChildren = true;
}
this.openmct.router.on('change:path', this.highlightIfNavigated);
},
destroy() {
destroyed() {
this.openmct.router.off('change:path', this.highlightIfNavigated);
if (this.composition) {
this.composition.off('add', this.addChild);
this.composition.off('remove', this.removeChild);
this.openmct.router.off('change:path', this.highlightIfNavigated);
delete this.composition;
}
},

View File

@ -18,7 +18,7 @@ export default {
this.objectPath.forEach(object => {
if (object) {
this.$once('hook:destroy',
this.$once('hook:destroyed',
this.openmct.objects.observe(object, '*', updateObject.bind(this, object)))
}
});

View File

@ -116,7 +116,7 @@
this.notebookEnabled = true;
}
},
destroy() {
destroyed() {
this.view.destroy();
}
}