Repository navigation
fix: memory leak in aiSearchModel - #342528
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix preserves lifecycle cleanup and adds targeted regression coverage, with no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes retained AI search folder roots by relying on the existing search-result disposal lifecycle.
Changes:
- Removes heading-level retention of AI folder roots and uses a one-shot disposal listener.
- Adds a regression test covering repeated search clearing and model disposal.
| File | Description |
|---|---|
| src/vs/workbench/contrib/search/test/browser/searchModel.test.ts | Verifies cleared AI roots are disposed only once. |
| src/vs/workbench/contrib/search/browser/AISearch/aiSearchModel.ts | Removes redundant root ownership and cleans up listeners on disposal. |
Review effort: Balanced
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
Please see review comment
|
[ai] feedback implemented Addressed the pending-root cleanup feedback in 7ccd778.
Validation: 50 Chromium search unit tests passed; client build, full client typecheck, and targeted ESLint passed. The 16-case reproduction matrix passed, and 100 cleanup cycles in each of the natural and explicitly model-bound control cases left no retained roots/file matches or editor listeners while the result model remained alive. These targeted checks cover disposal and request handling; a full Electron UI run was not performed. |
|
Simon Siefke (@SimonSiefke) Thank you! |

Details
Each search creates AI workspace folder roots and registers them in the search heading’s disposable store. Clearing the results disposes the roots, but does not remove them from that store, so old roots accumulate across searches.
Change
Use the existing search-result lifecycle to dispose AI folder roots and a one-shot disposal listener to remove the change listener.
Before
When running search/replace 37 times, AI folder-root allocations and their callbacks grow by 74:
After
No more leak detected.
Test Video
search-replace.webm
AI disclosure: Model: GPT 6.1 Sol. Worktime: 10 min