Skip to content

Commit

Permalink
Fix memory leak in ApplicationShell#activateWidget (eclipse-theia#10570)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Jan 5, 2022
1 parent ff1121f commit 2352920
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Emitter } from '../../common/event';
import { waitForRevealed, waitForClosed } from '../widgets';
import { CorePreferences } from '../core-preferences';
import { BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer';
import { Deferred } from '../../common/promise-util';

/** The class name added to ApplicationShell instances. */
const APPLICATION_SHELL_CLASS = 'theia-ApplicationShell';
Expand Down Expand Up @@ -1076,25 +1077,27 @@ export class ApplicationShell extends Widget {
if (!current) {
return undefined;
}
await Promise.all([
return Promise.all([
this.waitForActivation(current.id),
waitForRevealed(current),
this.pendingUpdates
]);
return current;
]).then(() => current, () => undefined);
}

waitForActivation(id: string): Promise<void> {
if (this.activeWidget && this.activeWidget.id === id) {
return Promise.resolve();
}
return new Promise(resolve => {
const toDispose = this.onDidChangeActiveWidget(() => {
if (this.activeWidget && this.activeWidget.id === id) {
toDispose.dispose();
resolve();
}
});
const activation = new Deferred();
const success = this.onDidChangeActiveWidget(() => {
if (this.activeWidget && this.activeWidget.id === id) {
activation.resolve();
}
});
const failure = setTimeout(() => activation.reject(new Error(`Widget with id '${id}' failed to activate.`)), this.activationTimeout + 250);
return activation.promise.finally(() => {
success.dispose();
clearTimeout(failure);
});
}

Expand Down

0 comments on commit 2352920

Please sign in to comment.