Merge pull request #282246 from SimonSiefke/fix/memory-leak-status-bar

fix: memory leak in status bar
This commit is contained in:
Johannes Rieken
2025-12-16 11:25:36 +01:00
committed by GitHub
@@ -6,7 +6,7 @@
import { MainThreadStatusBarShape, MainContext, ExtHostContext, StatusBarItemDto, ExtHostStatusBarShape } from '../common/extHost.protocol.js';
import { ThemeColor } from '../../../base/common/themables.js';
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
import { DisposableStore, toDisposable } from '../../../base/common/lifecycle.js';
import { DisposableMap, toDisposable, Disposable } from '../../../base/common/lifecycle.js';
import { Command } from '../../../editor/common/languages.js';
import { IAccessibilityInformation } from '../../../platform/accessibility/common/accessibility.js';
import { IMarkdownString } from '../../../base/common/htmlContent.js';
@@ -16,15 +16,16 @@ import { IManagedHoverTooltipMarkdownString } from '../../../base/browser/ui/hov
import { CancellationToken } from '../../../base/common/cancellation.js';
@extHostNamedCustomer(MainContext.MainThreadStatusBar)
export class MainThreadStatusBar implements MainThreadStatusBarShape {
export class MainThreadStatusBar extends Disposable implements MainThreadStatusBarShape {
private readonly _proxy: ExtHostStatusBarShape;
private readonly _store = new DisposableStore();
private readonly _entryDisposables = this._register(new DisposableMap<string>());
constructor(
extHostContext: IExtHostContext,
@IExtensionStatusBarItemService private readonly statusbarService: IExtensionStatusBarItemService
) {
super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostStatusBar);
// once, at startup read existing items and send them over
@@ -35,7 +36,7 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
this._proxy.$acceptStaticEntries(entries);
this._store.add(statusbarService.onDidChange(e => {
this._register(statusbarService.onDidChange(e => {
if (e.added) {
this._proxy.$acceptStaticEntries([asDto(e.added[0], e.added[1])]);
}
@@ -55,10 +56,6 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
}
}
dispose(): void {
this._store.dispose();
}
$setEntry(entryId: string, id: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, hasTooltipProvider: boolean, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): void {
const tooltipOrTooltipProvider = hasTooltipProvider
? {
@@ -71,11 +68,12 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
const kind = this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltipOrTooltipProvider, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
if (kind === StatusBarUpdateKind.DidDefine) {
this._store.add(toDisposable(() => this.statusbarService.unsetEntry(entryId)));
const disposable = toDisposable(() => this.statusbarService.unsetEntry(entryId));
this._entryDisposables.set(entryId, disposable);
}
}
$disposeEntry(entryId: string) {
this.statusbarService.unsetEntry(entryId);
this._entryDisposables.deleteAndDispose(entryId);
}
}