Skip to content

Commit

Permalink
Fix memory leak in vislib on auto refresh (#24134) (#24206)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes committed Oct 18, 2018
1 parent 46d05b6 commit 22aad41
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/ui/public/vis/vis_types/vislib_vis_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
constructor(el, vis) {
this.el = el;
this.vis = vis;
this.$scope = null;

this.container = document.createElement('div');
this.container.className = 'vislib-container';
Expand All @@ -65,20 +66,19 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
return resolve();
}

let $scope;
if (this.vis.params.addLegend) {
$(this.container).attr('class', (i, cls) => {
return cls.replace(/vislib-container--legend-\S+/g, '');
}).addClass(legendClassName[this.vis.params.legendPosition]);

$scope = $rootScope.$new();
$scope.refreshLegend = 0;
$scope.vis = this.vis;
$scope.visData = esResponse;
$scope.uiState = $scope.vis.getUiState();
const legendHtml = $compile('<vislib-legend></vislib-legend>')($scope);
this.$scope = $rootScope.$new();
this.$scope.refreshLegend = 0;
this.$scope.vis = this.vis;
this.$scope.visData = esResponse;
this.$scope.uiState = this.$scope.vis.getUiState();
const legendHtml = $compile('<vislib-legend></vislib-legend>')(this.$scope);
this.container.appendChild(legendHtml[0]);
$scope.$digest();
this.$scope.$digest();
}

this.vis.vislibVis = new vislib.Vis(this.chartEl, this.vis.params);
Expand All @@ -88,8 +88,8 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
this.vis.vislibVis.render(esResponse, this.vis.getUiState());

if (this.vis.params.addLegend) {
$scope.refreshLegend++;
$scope.$digest();
this.$scope.refreshLegend++;
this.$scope.$digest();
}
});
}
Expand All @@ -102,6 +102,10 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
delete this.vis.vislibVis;
}
$(this.container).find('vislib-legend').remove();
if (this.$scope) {
this.$scope.$destroy();
this.$scope = null;
}
}
}

Expand Down

0 comments on commit 22aad41

Please sign in to comment.