Skip to content

fix: memory leak in word highlighter - #346673

Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-word-highlight-ids
Nov 9, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-word-highlight-ids

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

The word highlighter stores decoration IDs in a static resource map. When an editor detaches or replaces its model, cleanup uses the editor’s current model and leaves the old resource’s IDs in that map.

Change

Use the highlighter’s original model to remove stale IDs when the editor changes models, and preserve them while another editor still displays that resource.

Before

When opening and closing JSON documents 17 times, stale highlight entries grow from 2 to 18, adding 256 bytes of decoration-ID strings. Total string growth is 27,472 bytes and 636 strings.

Before

After

Stale highlight entries remain at zero. Total string growth is 27,100 bytes and 618 strings; other allocations remain, and only the 256-byte decoration-ID saving is attributed to this fix.

After

Test Video

word-highlight-ids-native.webm

AI disclosure: Model: GPT 6.1 Sol. Worktime: 13 min

Copilot AI balanced review requested due to automatic review settings November 6, 2026 22:30

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.

🟢 Approval recommended

No active review issues are reported for the word-highlighter decoration cleanup change.

No open issues 🎉

What changed in this PR

Fixes a word-highlighter memory leak by cleaning up stored decoration IDs for the original model when an editor detaches or replaces it.

Changes:

  • Removes stale IDs unless another editor with a highlighter still displays the resource.
  • Adds regression tests for model detachment, replacement, disposal, and shared-editor cleanup.
File Description
src/​vs/​editor/​contrib/​wordHighlighter/​test/​browser/​wordHighlighter.test.ts Adds lifecycle and shared-model regression tests.
src/​vs/​editor/​contrib/​wordHighlighter/​browser/​wordHighlighter.ts Cleans up the original model’s stored decoration IDs while preserving shared ownership.

Review effort: Balanced

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.

🟡 Changes recommended

The new notebook-cell tests leave the static WordHighlighter.query uncleared, making the disabled-highlighting test order-dependent because subsequent highlighters can start provider requests during construction.

1 open issue

Review effort: Max

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please consider CCR feedback.

@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Added some minor test changes to address Copilot feedback!

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.

🟢 Approval recommended

There are no active review issues for the word-highlighter decoration cleanup change.

No open issues 🎉

1 resolved since last review

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 4452c9b into microsoft:main Nov 9, 2026
93 of 95 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 9, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-word-highlight-ids branch November 11, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues

5 participants