Repository navigation
Release accessible view listeners per show instead of on dispose - #337857
Dmitriy Vasyura (dmitrivMS) merged 6 commits into
Conversation
AccessibleView registered provider listeners (content changes, clear last provider, code block context) into its own store on every show and dropped the listeners of content refreshes. Every provider ever shown was retained for the lifetime of the window, e.g. every terminal whose accessible view was opened, including its TerminalInstance, xterm and DOM. Related to #146841 Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The terminal provider bypasses the new clear listener and can still be retained after terminal disposal.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Refactors AccessibleView listener lifetimes to prevent retained providers and detached UI resources.
Changes:
- Scopes provider and render listeners to each view lifecycle.
- Reuses code-block registration and replaces transient disposable stores.
- Adds listener cleanup coverage.
| File | Description |
|---|---|
accessibleView.ts |
Refactors listener and disposable ownership. |
accessibleView.test.ts |
Tests provider-listener cleanup. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The clear-last-provider listener was only installed for AccessibleContentProvider instances, which excludes TerminalAccessibleBufferProvider. The terminal provider also lost its clear notification when the accessible view disposed it on hide, so tie it to the terminal instance lifetime. Co-authored-by: Copilot <[email protected]>
…lp copies - Create the context view cleanup once in render instead of returning a new tracked disposable from every _render call; refreshes discarded it. - Copies of the current provider made for accessibility help use the structural provider check and forward onDidRequestClearLastProvider, so a terminal restored after the help view can still be cleared. - Drop the unused _updateLastProvider() call in onHide that created an untracked provider copy on every hide. - Tests render through a context view mock that behaves like the real one. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Accessibility Help can restore a terminal provider after its clear event already fired, retaining the disposed terminal.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Resolved since last review (1)
…s open Closing accessibility help restored its copy of the last provider unconditionally. If the provider requested to be cleared while help was open (e.g. its terminal was killed), the copy was remembered again after the clear notification was gone, retaining the killed terminal. Co-authored-by: Copilot <[email protected]>
Editor contributions register their own key listeners when the accessible view's text model gets attached, which happens asynchronously and, on macOS, added listeners after the baseline was taken. Take the baseline once the model is attached. Co-authored-by: Copilot <[email protected]>
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
…rosoft#337857) * Release accessible view listeners per show instead of on dispose AccessibleView registered provider listeners (content changes, clear last provider, code block context) into its own store on every show and dropped the listeners of content refreshes. Every provider ever shown was retained for the lifetime of the window, e.g. every terminal whose accessible view was opened, including its TerminalInstance, xterm and DOM. Related to microsoft#146841 Co-authored-by: Copilot <[email protected]> * Honor clear requests of directly implemented providers The clear-last-provider listener was only installed for AccessibleContentProvider instances, which excludes TerminalAccessibleBufferProvider. The terminal provider also lost its clear notification when the accessible view disposed it on hide, so tie it to the terminal instance lifetime. Co-authored-by: Copilot <[email protected]> * Address review: own render cleanup once and keep clear requests on help copies - Create the context view cleanup once in render instead of returning a new tracked disposable from every _render call; refreshes discarded it. - Copies of the current provider made for accessibility help use the structural provider check and forward onDidRequestClearLastProvider, so a terminal restored after the help view can still be cleared. - Drop the unused _updateLastProvider() call in onHide that created an untracked provider copy on every hide. - Tests render through a context view mock that behaves like the real one. Co-authored-by: Copilot <[email protected]> * Don't restore a provider that was cleared while accessibility help was open Closing accessibility help restored its copy of the last provider unconditionally. If the provider requested to be cleared while help was open (e.g. its terminal was killed), the copy was remembered again after the clear notification was gone, retaining the killed terminal. Co-authored-by: Copilot <[email protected]> * Make render listener test independent of model attach timing Editor contributions register their own key listeners when the accessible view's text model gets attached, which happens asynchronously and, on macOS, added listeners after the baseline was taken. Take the baseline once the model is attached. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit 2bebb11)

Related to #146841 (replaces the
AccessibilityHelpWidgetitem of the issue, which becameAccessibleView)AccessibleViewis a long-lived singleton, butshow()registered per-provider listeners into its own_storeon every call:provider.onDidChangeContentlistenerprovider.onDidRequestClearLastProviderlistenerand
_render()returned a new listener store on every content refresh, which was dropped when refreshing an already visible view. So every provider ever shown was retained for the lifetime of the window — for the terminal that is the wholeTerminalInstance, xterm and DOM of every terminal whose accessible view was ever opened, even after the terminal was killed.Now listeners of a
show()are released when the view hides, render listeners replace the previous set, the clear-last-provider listener lives as long as that provider is remembered, and the code block context provider is registered once.Retainer path (heap snapshot, before):
AccessibleViewService → AccessibleView._store → FunctionDisposable → listener closure → TerminalAccessibleBufferProvider._instance → TerminalInstance._wrapperElement → <div class="terminal-wrapper">The clear-last-provider listener now uses the structural provider contract, so providers implementing
IAccessibleViewContentProviderdirectly (likeTerminalAccessibleBufferProvider) are honored. The terminal provider's clear notification is tied to the terminal instance instead of the provider, because the accessible view disposes the provider on hide while it may still remember it. Copies of the provider made for Accessibility Help (and restored when it closes) forward the clear request too.Measurement
echo hello, Open Accessible View, Escape, kill terminal)TerminalInstance, 5XtermTerminal, 5TerminalAccessibleBufferProvider, 5BufferContentTrackeralive; 5 detached terminal DOM trees (+26 detached roots / +96 nodes)This is unbounded: it grows by one terminal per terminal whose accessible view was opened (live object counts from heap snapshots after GC).
How this was measured
Code OSS (Electron, dev build) driven over CDP with Playwright. After each scenario: 4× forced GC, then
DOM.getDetachedDomNodes(the data behind Edge's Detached Elements tool), counting the descendants of every detached root. "Without this change" means all other fixes from this series applied and only this one reverted, so the number shows what this retainer alone keeps alive. Each scenario was run 3 times with identical results. The retainer was identified from a heap snapshot retainer path.Added a unit test that provider listeners don't accumulate across show() calls and are released when the view hides.