mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
hunting memory leaks
This commit is contained in:
@@ -117,9 +117,10 @@ export class DashboardCtrl {
|
|||||||
$timeout.cancel(resizeEventTimeout);
|
$timeout.cancel(resizeEventTimeout);
|
||||||
resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
|
resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
|
||||||
});
|
});
|
||||||
var unbind = $scope.$on('$destroy', function() {
|
|
||||||
|
$scope.$on('$destroy', function() {
|
||||||
angular.element(window).unbind('resize');
|
angular.element(window).unbind('resize');
|
||||||
unbind();
|
$scope.dashboard.destroy();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,10 +130,10 @@ export class DashboardCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init(dashboard) {
|
init(dashboard) {
|
||||||
this.$scope.registerWindowResizeEvent();
|
|
||||||
this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor);
|
this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor);
|
||||||
this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated);
|
this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated);
|
||||||
this.$scope.setupDashboard(dashboard);
|
this.$scope.setupDashboard(dashboard);
|
||||||
|
this.$scope.registerWindowResizeEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,6 +247,13 @@ export class DashboardModel {
|
|||||||
moment.utc(date).format(format);
|
moment.utc(date).format(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.events.removeAllListeners();
|
||||||
|
for (let row of this.rows) {
|
||||||
|
row.events.removeAllListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getRelativeTime(date) {
|
getRelativeTime(date) {
|
||||||
date = moment.isMoment(date) ? date : moment(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('panel-added', updateState);
|
||||||
row.events.on('span-changed', 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() {
|
scope.$on("ANGULAR_DRAG_START", function() {
|
||||||
indrag = true;
|
indrag = true;
|
||||||
|
|||||||
@@ -12,16 +12,15 @@ function(angular, _) {
|
|||||||
function Tracker(dashboard, scope) {
|
function Tracker(dashboard, scope) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.original = dashboard.getSaveModelClone();
|
|
||||||
this.current = dashboard;
|
this.current = dashboard;
|
||||||
this.originalPath = $location.path();
|
this.originalPath = $location.path();
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
|
|
||||||
// register events
|
// register events
|
||||||
scope.onAppEvent('dashboard-saved', function() {
|
scope.onAppEvent('dashboard-saved', function() {
|
||||||
self.original = self.current.getSaveModelClone();
|
this.original = this.current.getSaveModelClone();
|
||||||
self.originalPath = $location.path();
|
this.originalPath = $location.path();
|
||||||
});
|
}.bind(this));
|
||||||
|
|
||||||
$window.onbeforeunload = function() {
|
$window.onbeforeunload = function() {
|
||||||
if (self.ignoreChanges()) { return; }
|
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;
|
var p = Tracker.prototype;
|
||||||
@@ -153,8 +157,7 @@ function(angular, _) {
|
|||||||
|
|
||||||
this.Tracker = Tracker;
|
this.Tracker = Tracker;
|
||||||
this.init = function(dashboard, scope) {
|
this.init = function(dashboard, scope) {
|
||||||
// wait for different services to patch the dashboard (missing properties)
|
new Tracker(dashboard, scope);
|
||||||
$timeout(function() { new Tracker(dashboard, scope); }, 1200);
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,11 +50,9 @@ export class PanelCtrl {
|
|||||||
|
|
||||||
$scope.$on("refresh", () => this.refresh());
|
$scope.$on("refresh", () => this.refresh());
|
||||||
$scope.$on("render", () => this.render());
|
$scope.$on("render", () => this.render());
|
||||||
|
$scope.$on("$destroy", () => {
|
||||||
var unbindDestroy = $scope.$on("$destroy", () => {
|
|
||||||
this.events.emit('panel-teardown');
|
this.events.emit('panel-teardown');
|
||||||
this.events.removeAllListeners();
|
this.events.removeAllListeners();
|
||||||
unbindDestroy();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user