Skip to content

Commit

Permalink
Fix Leaking TraceViewerWidget instances
Browse files Browse the repository at this point in the history
Making use of toDispose.push in Trace Viewer Widget to dispose its event listeners so that they
don't cause memory leaks

Fixes #730

Signed-off-by: hriday-panchasara <hriday.panchasara@ericsson.com>
  • Loading branch information
hriday-panchasara authored and bhufmann committed Sep 7, 2022
1 parent 6102821 commit ddfed7c
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DisposableCollection, MessageService, Path } from '@theia/core';
import { Disposable, DisposableCollection, MessageService, Path } from '@theia/core';
import { ApplicationShell, Message, StatusBar, WidgetManager, StatefulWidget } from '@theia/core/lib/browser';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { inject, injectable, postConstruct } from 'inversify';
Expand Down Expand Up @@ -92,19 +92,22 @@ export class TraceViewerWidget extends ReactWidget implements StatefulWidget {
this.title.closable = true;
this.addClass('theia-trace-open');
this.backgroundTheme = this.themeService.getCurrentTheme().type;
this.themeService.onDidColorThemeChange(() => this.updateBackgroundTheme());
this.toDispose.push(this.themeService.onDidColorThemeChange(() => this.updateBackgroundTheme()));
if (!this.options.traceUUID) {
this.initialize();
}
this.traceContextComponent = React.createRef();
this.tspClient = this.tspClientProvider.getTspClient();
this.traceManager = this.tspClientProvider.getTraceManager();
this.experimentManager = this.tspClientProvider.getExperimentManager();
this.tspClientProvider.addTspClientChangeListener(tspClient => {
this.tspClient = tspClient;
this.traceManager = this.tspClientProvider.getTraceManager();
this.experimentManager = this.tspClientProvider.getExperimentManager();
});
this.toDispose.push(Disposable.create(() => {
this.tspClientProvider.addTspClientChangeListener(tspClient => {
this.tspClient = tspClient;
this.traceManager = this.tspClientProvider.getTraceManager();
this.experimentManager = this.tspClientProvider.getExperimentManager();
});
}));

if (this.options.traceUUID) {
const experiment = await this.experimentManager.updateExperiment(this.options.traceUUID);
if (experiment) {
Expand Down

0 comments on commit ddfed7c

Please sign in to comment.