You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak: LSP client diagnostics and files maps not cleared on shutdown #9143
These issues all address memory retention and cleanup problems in OpenCode, including LSP-related memory leaks. Your proposed fix for clearing diagnostics and files maps in LSPClient.shutdown() is directly addressing part of the root cause identified in #9140 regarding unbounded caches.
Feel free to ignore if your specific case differs from these.
changed the title [-]LSP client diagnostics and files maps not cleared on shutdown[/-][+]Memory leak: LSP client diagnostics and files maps not cleared on shutdown[/+]on Jan 18, 2026
Lifecycle is tied to the LSP client - Both maps are naturally garbage collected when the client calls shutdown() (line 239-245) and the client object is released.
diagnostics is self-updating - When the LSP server clears diagnostics for a file, it sends an empty array via publishDiagnostics, which updates the map correctly. It's also
cleared on file open (line 194).
files versioning is needed - The version numbers must persist to correctly distinguish between didOpen vs didChange notifications. Clearing this could cause protocol issues
if a file is re-opened (version conflicts).
Memory impact is minimal - These store string keys with small values (arrays or numbers). Even with hundreds of files, the memory footprint is negligible.
When you might want to consider it:
If the LSP client lives for extremely long sessions with thousands of unique files being touched
If you implement a textDocument/didClose notification (currently missing), you could clean up both maps when a file is explicitly closed
For typical usage patterns, the current design is fine.
Activity
github-actions commentedon Jan 17, 2026
This issue might be a duplicate of or closely related to existing memory management issues. Please check:
These issues all address memory retention and cleanup problems in OpenCode, including LSP-related memory leaks. Your proposed fix for clearing diagnostics and files maps in LSPClient.shutdown() is directly addressing part of the root cause identified in #9140 regarding unbounded caches.
Feel free to ignore if your specific case differs from these.
[-]LSP client diagnostics and files maps not cleared on shutdown[/-][+]Memory leak: LSP client diagnostics and files maps not cleared on shutdown[/+]aptor9 commentedon Jan 19, 2026
This is what I got from claude. Maybe worth a double check?
● Looking at this code, there are two data structures that accumulate state:
Short answer: No, you likely don't need to.
Here's why:
cleared on file open (line 194).
if a file is re-opened (version conflicts).
When you might want to consider it:
For typical usage patterns, the current design is fine.
sauerdaniel commentedon Jan 19, 2026
This was already fixed in commit f936043dd (Jan 15, 2026):
The fix is exactly as proposed in this issue. See: f936043