Skip to content

fix: memory leak in notebookCellLinkifier - #340149

Open
Simon Siefke (SimonSiefke) wants to merge 14 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-notebook-cell-linkifier
Open

Simon Siefke (SimonSiefke) wants to merge 14 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-notebook-cell-linkifier

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Repeated notebook cell lookups register the same workspace listeners again because the initialized flag is never set.

Change

Set the initialized flag, clear old cell IDs when rebuilding the index, and remove notebook entries when they close.

Before

Across 37 chat responses with three notebook cell links each, clearing chat after every response, named-function-count3 detects +111 per notebook callback. The red box marks rows with reduced growth after the fix.

notebook-functions-before-highlighted

After

Callback growth drops to +37 per callback. A separate leak remains: each response creates a linkifier that stays until feature deactivation (+37 instances).

notebook-functions-after

Test Video

notebook-cell-links.mp4

AI disclosure: Model: Some kind of OpenAI model. Worktime: n/a

Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The last-notebook close path bypasses the newly added WeakMap cleanup.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes repeated notebook listener registration and stale cell-ID tracking.

Changes:

  • Initializes listeners once per linkifier.
  • Clears stale IDs and removes closed notebook entries.
  • Adds listener lifecycle coverage.
File Description
notebookCellLinkifier.ts Updates listener and cell-ID lifecycle cleanup.
notebookCellLinkifier.spec.ts Tests listener registration and disposal.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread extensions/copilot/src/extension/linkify/vscode-node/notebookCellLinkifier.ts Outdated

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants