Commit ca1f06f1 by Torkel Ödegaard

hunting memory leaks

parent 4d420a0c
......@@ -117,9 +117,10 @@ export class DashboardCtrl {
$timeout.cancel(resizeEventTimeout);
resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
});
var unbind = $scope.$on('$destroy', function() {
$scope.$on('$destroy', function() {
angular.element(window).unbind('resize');
unbind();
$scope.dashboard.destroy();
});
};
......@@ -129,10 +130,10 @@ export class DashboardCtrl {
}
init(dashboard) {
this.$scope.registerWindowResizeEvent();
this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor);
this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated);
this.$scope.setupDashboard(dashboard);
this.$scope.registerWindowResizeEvent();
}
}
......
......@@ -247,6 +247,13 @@ export class DashboardModel {
moment.utc(date).format(format);
}
destroy() {
this.events.removeAllListeners();
for (let row of this.rows) {
row.events.removeAllListeners();
}
}
getRelativeTime(date) {
date = moment.isMoment(date) ? date : moment(date);
......
......@@ -212,7 +212,11 @@ coreModule.directive('panelDropZone', function($timeout) {
row.events.on('panel-added', updateState);
row.events.on('span-changed', updateState);
//scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState);
scope.$on('$destroy', () => {
row.events.off('panel-added', updateState);
row.events.off('span-changed', updateState);
});
// scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState);
scope.$on("ANGULAR_DRAG_START", function() {
indrag = true;
......
......@@ -12,16 +12,15 @@ function(angular, _) {
function Tracker(dashboard, scope) {
var self = this;
this.original = dashboard.getSaveModelClone();
this.current = dashboard;
this.originalPath = $location.path();
this.scope = scope;
// register events
scope.onAppEvent('dashboard-saved', function() {
self.original = self.current.getSaveModelClone();
self.originalPath = $location.path();
});
this.original = this.current.getSaveModelClone();
this.originalPath = $location.path();
}.bind(this));
$window.onbeforeunload = function() {
if (self.ignoreChanges()) { return; }
......@@ -44,6 +43,11 @@ function(angular, _) {
});
}
});
// wait for different services to patch the dashboard (missing properties)
$timeout(function() {
self.original = dashboard.getSaveModelClone();
}, 1000);
}
var p = Tracker.prototype;
......@@ -153,8 +157,7 @@ function(angular, _) {
this.Tracker = Tracker;
this.init = function(dashboard, scope) {
// wait for different services to patch the dashboard (missing properties)
$timeout(function() { new Tracker(dashboard, scope); }, 1200);
new Tracker(dashboard, scope);
};
});
});
......@@ -50,11 +50,9 @@ export class PanelCtrl {
$scope.$on("refresh", () => this.refresh());
$scope.$on("render", () => this.render());
var unbindDestroy = $scope.$on("$destroy", () => {
$scope.$on("$destroy", () => {
this.events.emit('panel-teardown');
this.events.removeAllListeners();
unbindDestroy();
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment