Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix memory leak in vislib on auto refresh (#24134) #24206

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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