fix: dispose createModelReference ref on stale element in disassemblyView#305995
fix: dispose createModelReference ref on stale element in disassemblyView#305995
Conversation
…entInner Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/b38a7565-be21-41f7-a4ab-e6cbc1c8aadb Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a resource leak in the Debug Disassembly View’s instruction renderer by ensuring ITextModelService.createModelReference() results are disposed when an async render detects the element has become stale.
Changes:
- Dispose the acquired model reference before early-returning on the stale-element race guard in
InstructionRenderer.renderElementInner.
| @@ -862,7 +862,8 @@ class InstructionRenderer extends Disposable implements ITableRenderer<IDisassem | |||
| const sourceSB = new StringBuilder(10000); | |||
| const ref = await this.textModelService.createModelReference(sourceURI); | |||
There was a problem hiding this comment.
The new stale-element guard disposes the ref when the template is reused, but the same async race can still leak when the row/template gets disposed (e.g. list/view disposed) while awaiting createModelReference: currentElement.element remains element, so the guard won’t trigger and the ref can be pushed after disposeElement has already run. Consider clearing templateData.currentElement.element in disposeElement (or tracking a render/dispose token) so the post-await check reliably detects disposed templates and disposes the ref before returning/continuing.
| const ref = await this.textModelService.createModelReference(sourceURI); | |
| const ref = await this.textModelService.createModelReference(sourceURI); | |
| // If the template has been disposed while awaiting the model, its DOM node will be detached. | |
| // In that case, dispose the ref and stop to avoid leaking the model or touching stale DOM. | |
| if (!templateData.sourcecode.isConnected) { | |
| ref.dispose(); | |
| return; | |
| } |
In
renderElementInner, the model reference acquired viacreateModelReferencewas leaked when the async race guard detected a stale element — the ref was never disposed before the early return.Changes
disassemblyView.ts: Callref.dispose()before returning whentemplateData.currentElement.element !== element, preventing the model reference leak on the stale-element code path.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.