Change:
I was trying to understand the usage of and the lifecycle of actions created while creating it. I think this originated with the terminal, so looked at the terminal code, but it seems like the problem isn't solved here either. instantiates some Actions which extend Disposable, but they are never tracked or disposed. The ActionViewItems returned from are apparently owned by whatever calls that and get disposed, but not these extra actions that we have to create. So, one solution would be for them to be owned and disposed by although that feels unexpected. But otherwise, there isn't a technically correct way for the code in to know when they should be disposed. Wondering whether I'm missing something or if you have any thoughts.
I spent some time investigating this and the issue is that we use in some places and in others. Only the latter is disposable. This would be a bit involved to rework

Discussion:
import * as dom from 'vs/base/browser/dom'; import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; <del> import { IAction } from 'vs/base/common/actions'; </del> <ins> import { Action, IAction } from 'vs/base/common/actions'; </ins> import { CancellationToken } from 'vs/base/common/cancellation'; import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem'; import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';

import { ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService'; import { IBaseActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems'; <ins> import { DisposableStore } from 'vs/base/common/lifecycle'; </ins> export class TerminalEditor extends EditorPane {

private _cancelContextMenu: boolean = false; <ins> private _disposableStore = this._register(new DisposableStore()); </ins> constructor( group: IEditorGroup, @ITelemetryService telemetryService: ITelemetryService,

if (action instanceof MenuItemAction) { const location = { viewColumn: ACTIVE_GROUP }; const actions = getTerminalActionBarArgs(location, this._terminalProfileService.availableProfiles, this._getDefaultProfileName(), this._terminalProfileService.contributedProfiles, this._terminalService, this._dropdownMenu); <ins> this._registerDisposableActions(actions.dropdownAction, actions.dropdownMenuActions); </ins> const button = this._instantiationService.createInstance(DropdownWithPrimaryActionViewItem, action, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, { hoverDelegate: options.hoverDelegate }); return button; }

import { getColorForSeverity } from 'vs/workbench/contrib/terminal/browser/terminalStatusList'; import { createAndFillInContextMenuActions, MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem'; <del> import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; </del> <ins> import { DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; </ins> import { URI } from 'vs/base/common/uri'; import { ColorScheme } from 'vs/platform/theme/common/theme'; import { getColorClass, getUriClasses } from 'vs/workbench/contrib/terminal/browser/terminalIcon';

private readonly _dropdownMenu: IMenu; private readonly _singleTabMenu: IMenu; private _viewShowing: IContextKey<boolean>; <ins> private _disposableStore = this._register(new DisposableStore()); </ins> constructor( options: IViewPaneOptions,

case TerminalCommandId.New: { if (action instanceof MenuItemAction) { const actions = getTerminalActionBarArgs(TerminalLocation.Panel, this._terminalProfileService.availableProfiles, this._getDefaultProfileName(), this._terminalProfileService.contributedProfiles, this._terminalService, this._dropdownMenu); <ins> this._registerDisposableActions(actions.dropdownAction, actions.dropdownMenuActions); </ins> this._newDropdown?.dispose(); this._newDropdown = new DropdownWithPrimaryActionViewItem(action, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, { hoverDelegate: options.hoverDelegate }, this._keybindingService, this._notificationService, this._contextKeyService, this._themeService, this._accessibilityService); this._updateTabActionBar(this._terminalProfileService.availableProfiles);

return super.getActionViewItem(action, options); } <ins> /** * Actions might be of type Action (disposable) or Separator or SubmenuAction, which don't extend Disposable */ private _registerDisposableActions(dropdownAction: IAction, dropdownMenuActions: IAction[]): void { this._disposableStore.clear(); if (dropdownAction instanceof Action) { this._disposableStore.add(dropdownAction); } dropdownMenuActions.filter(a => a instanceof Action).forEach(a => this._disposableStore.add(a)); } </ins> private _getDefaultProfileName(): string { let defaultProfileName; try {

private _updateTabActionBar(profiles: ITerminalProfile[]): void { const actions = getTerminalActionBarArgs(TerminalLocation.Panel, profiles, this._getDefaultProfileName(), this._terminalProfileService.contributedProfiles, this._terminalService, this._dropdownMenu); <ins> this._registerDisposableActions(actions.dropdownAction, actions.dropdownMenuActions); </ins> this._newDropdown?.update(actions.dropdownAction, actions.dropdownMenuActions); }