Skip to content

Commit

Permalink
fix: memory leak in code editor widget (#205488)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSiefke authored Feb 19, 2024
1 parent d83cc26 commit b2b60ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/vs/editor/browser/widget/codeEditorContributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { getWindow, runWhenWindowIdle } from 'vs/base/browser/dom';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
import { Disposable, DisposableMap, IDisposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorContributionInstantiation, IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
Expand Down Expand Up @@ -111,10 +111,10 @@ export class CodeEditorContributions extends Disposable {
this._instantiateSome(EditorContributionInstantiation.BeforeFirstInteraction);
}

public onAfterModelAttached(): void {
this._register(runWhenWindowIdle(getWindow(this._editor?.getDomNode()), () => {
public onAfterModelAttached(): IDisposable {
return runWhenWindowIdle(getWindow(this._editor?.getDomNode()), () => {
this._instantiateSome(EditorContributionInstantiation.AfterFirstRender);
}, 50));
}, 50);
}

private _instantiateSome(instantiation: EditorContributionInstantiation): void {
Expand Down
6 changes: 4 additions & 2 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
private readonly _overflowWidgetsDomNode: HTMLElement | undefined;
private readonly _id: number;
private readonly _configuration: IEditorConfiguration;
private _contributionsDisposable: IDisposable | undefined;

protected readonly _actions = new Map<string, editorCommon.IEditorAction>();

Expand Down Expand Up @@ -523,7 +524,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._onDidChangeModel.fire(e);
this._postDetachModelCleanup(detachedModel);

this._contributions.onAfterModelAttached();
this._contributionsDisposable = this._contributions.onAfterModelAttached();
}

private _removeDecorationTypes(): void {
Expand Down Expand Up @@ -1871,6 +1872,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
}

private _detachModel(): ITextModel | null {
this._contributionsDisposable?.dispose();
this._contributionsDisposable = undefined;
if (!this._modelData) {
return null;
}
Expand All @@ -1887,7 +1890,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (this._bannerDomNode && this._domElement.contains(this._bannerDomNode)) {
this._domElement.removeChild(this._bannerDomNode);
}

return model;
}

Expand Down

0 comments on commit b2b60ac

Please sign in to comment.