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

fix: memory leak in code editor widget #205488

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
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
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();
hediet marked this conversation as resolved.
Show resolved Hide resolved
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
Loading