mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 13:48:12 +00:00
Memory leak fixes (#2387)
* Clean up listeners * Fix uses of 'destroy' instead of 'destroyed'
This commit is contained in:
committed by
Deep Tailor
parent
d2e2d55caf
commit
844280eaa5
@ -45,22 +45,27 @@ define([
|
|||||||
view: function (domainObject) {
|
view: function (domainObject) {
|
||||||
let $rootScope = openmct.$injector.get('$rootScope');
|
let $rootScope = openmct.$injector.get('$rootScope');
|
||||||
let templateLinker = openmct.$injector.get('templateLinker');
|
let templateLinker = openmct.$injector.get('templateLinker');
|
||||||
let scope = $rootScope.$new();
|
let scope = $rootScope.$new(true);
|
||||||
let legacyObject = convertToLegacyObject(domainObject);
|
let legacyObject = convertToLegacyObject(domainObject);
|
||||||
let isDestroyed = false;
|
let isDestroyed = false;
|
||||||
let unlistenToStatus;
|
let unlistenToStatus;
|
||||||
|
let element;
|
||||||
scope.domainObject = legacyObject;
|
scope.domainObject = legacyObject;
|
||||||
scope.model = legacyObject.getModel();
|
scope.model = legacyObject.getModel();
|
||||||
|
let child;
|
||||||
|
let parent;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
show: function (container) {
|
show: function (container) {
|
||||||
|
parent = container;
|
||||||
|
child = document.createElement('div');
|
||||||
|
parent.appendChild(child);
|
||||||
let statusCapability = legacyObject.getCapability('status');
|
let statusCapability = legacyObject.getCapability('status');
|
||||||
unlistenToStatus = statusCapability.listen((newStatus) => {
|
unlistenToStatus = statusCapability.listen((newStatus) => {
|
||||||
container.classList.remove('s-status-timeconductor-unsynced');
|
child.classList.remove('s-status-timeconductor-unsynced');
|
||||||
|
|
||||||
if (newStatus.includes('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) {
|
uses.forEach(function (key, i) {
|
||||||
scope[key] = results[i];
|
scope[key] = results[i];
|
||||||
});
|
});
|
||||||
|
element = openmct.$angular.element(child);
|
||||||
templateLinker.link(
|
templateLinker.link(
|
||||||
scope,
|
scope,
|
||||||
openmct.$angular.element(container),
|
element,
|
||||||
legacyView
|
legacyView
|
||||||
);
|
);
|
||||||
container.classList.add('u-contents');
|
child.classList.add('u-contents');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promises.length) {
|
if (promises.length) {
|
||||||
@ -103,7 +109,11 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
|
element.off();
|
||||||
|
element.remove();
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
|
element = null;
|
||||||
|
scope = null;
|
||||||
unlistenToStatus();
|
unlistenToStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,18 @@ define([
|
|||||||
let domainObject = selection[0][0].context.item;
|
let domainObject = selection[0][0].context.item;
|
||||||
let $rootScope = openmct.$injector.get('$rootScope');
|
let $rootScope = openmct.$injector.get('$rootScope');
|
||||||
let templateLinker = openmct.$injector.get('templateLinker');
|
let templateLinker = openmct.$injector.get('templateLinker');
|
||||||
let scope = $rootScope.$new();
|
let scope = $rootScope.$new(true);
|
||||||
let legacyObject = convertToLegacyObject(domainObject);
|
let legacyObject = convertToLegacyObject(domainObject);
|
||||||
let isDestroyed = false;
|
let isDestroyed = false;
|
||||||
|
let element;
|
||||||
scope.domainObject = legacyObject;
|
scope.domainObject = legacyObject;
|
||||||
scope.model = legacyObject.getModel();
|
scope.model = legacyObject.getModel();
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
show: function (container) {
|
show: function (container) {
|
||||||
|
let child = document.createElement('div');
|
||||||
|
container.appendChild(child);
|
||||||
// TODO: implement "gestures" support ?
|
// TODO: implement "gestures" support ?
|
||||||
let uses = representation.uses || [];
|
let uses = representation.uses || [];
|
||||||
let promises = [];
|
let promises = [];
|
||||||
@ -70,9 +73,10 @@ define([
|
|||||||
uses.forEach(function (key, i) {
|
uses.forEach(function (key, i) {
|
||||||
scope[key] = results[i];
|
scope[key] = results[i];
|
||||||
});
|
});
|
||||||
|
element = openmct.$angular.element(child)
|
||||||
templateLinker.link(
|
templateLinker.link(
|
||||||
scope,
|
scope,
|
||||||
openmct.$angular.element(container),
|
element,
|
||||||
representation
|
representation
|
||||||
);
|
);
|
||||||
container.style.height = '100%';
|
container.style.height = '100%';
|
||||||
@ -89,7 +93,11 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
|
element.off();
|
||||||
|
element.remove();
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
|
element = null;
|
||||||
|
scope = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ define([
|
|||||||
this.filteredRows.destroy();
|
this.filteredRows.destroy();
|
||||||
Object.keys(this.subscriptions).forEach(this.unsubscribe, this);
|
Object.keys(this.subscriptions).forEach(this.unsubscribe, this);
|
||||||
this.openmct.time.off('bounds', this.refreshData);
|
this.openmct.time.off('bounds', this.refreshData);
|
||||||
this.openmct.time.on('timeSystem', this.refreshData);
|
this.openmct.time.off('timeSystem', this.refreshData);
|
||||||
if (this.filterObserver) {
|
if (this.filterObserver) {
|
||||||
this.filterObserver();
|
this.filterObserver();
|
||||||
}
|
}
|
||||||
|
@ -70,17 +70,18 @@
|
|||||||
this.domainObject = newObject;
|
this.domainObject = newObject;
|
||||||
});
|
});
|
||||||
this.$once('hook:destroyed', removeListener);
|
this.$once('hook:destroyed', removeListener);
|
||||||
|
|
||||||
if (this.openmct.composition.get(this.node.object)) {
|
if (this.openmct.composition.get(this.node.object)) {
|
||||||
this.hasChildren = true;
|
this.hasChildren = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.openmct.router.on('change:path', this.highlightIfNavigated);
|
this.openmct.router.on('change:path', this.highlightIfNavigated);
|
||||||
},
|
},
|
||||||
destroy() {
|
destroyed() {
|
||||||
|
this.openmct.router.off('change:path', this.highlightIfNavigated);
|
||||||
if (this.composition) {
|
if (this.composition) {
|
||||||
this.composition.off('add', this.addChild);
|
this.composition.off('add', this.addChild);
|
||||||
this.composition.off('remove', this.removeChild);
|
this.composition.off('remove', this.removeChild);
|
||||||
this.openmct.router.off('change:path', this.highlightIfNavigated);
|
|
||||||
delete this.composition;
|
delete this.composition;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@ export default {
|
|||||||
|
|
||||||
this.objectPath.forEach(object => {
|
this.objectPath.forEach(object => {
|
||||||
if (object) {
|
if (object) {
|
||||||
this.$once('hook:destroy',
|
this.$once('hook:destroyed',
|
||||||
this.openmct.objects.observe(object, '*', updateObject.bind(this, object)))
|
this.openmct.objects.observe(object, '*', updateObject.bind(this, object)))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
this.notebookEnabled = true;
|
this.notebookEnabled = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroy() {
|
destroyed() {
|
||||||
this.view.destroy();
|
this.view.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user