Skip to content

Commit ca1f06f

Browse files
committed
hunting memory leaks
1 parent 4d420a0 commit ca1f06f

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

public/app/features/dashboard/dashboard_ctrl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ export class DashboardCtrl {
117117
$timeout.cancel(resizeEventTimeout);
118118
resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
119119
});
120-
var unbind = $scope.$on('$destroy', function() {
120+
121+
$scope.$on('$destroy', function() {
121122
angular.element(window).unbind('resize');
122-
unbind();
123+
$scope.dashboard.destroy();
123124
});
124125
};
125126

@@ -129,10 +130,10 @@ export class DashboardCtrl {
129130
}
130131

131132
init(dashboard) {
132-
this.$scope.registerWindowResizeEvent();
133133
this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor);
134134
this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated);
135135
this.$scope.setupDashboard(dashboard);
136+
this.$scope.registerWindowResizeEvent();
136137
}
137138
}
138139

public/app/features/dashboard/model.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ export class DashboardModel {
247247
moment.utc(date).format(format);
248248
}
249249

250+
destroy() {
251+
this.events.removeAllListeners();
252+
for (let row of this.rows) {
253+
row.events.removeAllListeners();
254+
}
255+
}
256+
250257
getRelativeTime(date) {
251258
date = moment.isMoment(date) ? date : moment(date);
252259

public/app/features/dashboard/row/row.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ coreModule.directive('panelDropZone', function($timeout) {
212212
row.events.on('panel-added', updateState);
213213
row.events.on('span-changed', updateState);
214214

215-
//scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState);
215+
scope.$on('$destroy', () => {
216+
row.events.off('panel-added', updateState);
217+
row.events.off('span-changed', updateState);
218+
});
219+
// scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState);
216220

217221
scope.$on("ANGULAR_DRAG_START", function() {
218222
indrag = true;

public/app/features/dashboard/unsavedChangesSrv.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ function(angular, _) {
1212
function Tracker(dashboard, scope) {
1313
var self = this;
1414

15-
this.original = dashboard.getSaveModelClone();
1615
this.current = dashboard;
1716
this.originalPath = $location.path();
1817
this.scope = scope;
1918

2019
// register events
2120
scope.onAppEvent('dashboard-saved', function() {
22-
self.original = self.current.getSaveModelClone();
23-
self.originalPath = $location.path();
24-
});
21+
this.original = this.current.getSaveModelClone();
22+
this.originalPath = $location.path();
23+
}.bind(this));
2524

2625
$window.onbeforeunload = function() {
2726
if (self.ignoreChanges()) { return; }
@@ -44,6 +43,11 @@ function(angular, _) {
4443
});
4544
}
4645
});
46+
47+
// wait for different services to patch the dashboard (missing properties)
48+
$timeout(function() {
49+
self.original = dashboard.getSaveModelClone();
50+
}, 1000);
4751
}
4852

4953
var p = Tracker.prototype;
@@ -153,8 +157,7 @@ function(angular, _) {
153157

154158
this.Tracker = Tracker;
155159
this.init = function(dashboard, scope) {
156-
// wait for different services to patch the dashboard (missing properties)
157-
$timeout(function() { new Tracker(dashboard, scope); }, 1200);
160+
new Tracker(dashboard, scope);
158161
};
159162
});
160163
});

public/app/features/panel/panel_ctrl.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ export class PanelCtrl {
5050

5151
$scope.$on("refresh", () => this.refresh());
5252
$scope.$on("render", () => this.render());
53-
54-
var unbindDestroy = $scope.$on("$destroy", () => {
53+
$scope.$on("$destroy", () => {
5554
this.events.emit('panel-teardown');
5655
this.events.removeAllListeners();
57-
unbindDestroy();
5856
});
5957
}
6058

0 commit comments

Comments
 (0)