Skip to content

Fix issue with Session not being garbage collected#2801

Merged
rchl merged 8 commits intomainfrom
fix/session-gc
Mar 11, 2026
Merged

Fix issue with Session not being garbage collected#2801
rchl merged 8 commits intomainfrom
fix/session-gc

Conversation

@rchl
Copy link
Copy Markdown
Member

@rchl rchl commented Mar 9, 2026

Sessions were not being garbage collected for two reasons:

  • In connection with request_handler / notification_handler decorators, we've stored reference to methods on self. Since methods have hard reference to self that created a cycle. Store only mapping from handler name to m_* handler and use that for calling the right function when m_* method is called.
  • The get_diagnostics_identifiers function uses lru_cache decorator which stores reference to Session. We need to clear the cache when session is destroyed. This is not a proper fix since it clears the whole cache instead of only caches related to ended session but I don't have time now to investigate it further. Addressed by switching to manual caching.

For testing one can add

    def __del__(self):
        print('DEL Session')

in Session to verify that session is destroyed on last file in the window being closed.

@rchl
Copy link
Copy Markdown
Member Author

rchl commented Mar 10, 2026

Switched to manual caching for diagnostic identifiers.

Comment thread plugin/documents.py
# Have to do this on the main thread, since __init__ and __del__ are invoked on the main thread too
self._cleanup()
self._setup()
get_diagnostics_identifiers.cache_clear()
Copy link
Copy Markdown
Member

@jwortmann jwortmann Mar 10, 2026

Choose a reason for hiding this comment

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

_reset is called when either the syntax or the URI of the view changes:

LSP/plugin/documents.py

Lines 1128 to 1129 in e74ce6b

if something_changed:
self._reset()

In that case the DocumentSelector might not match anymore for the diagnostic provider(s). That is the reason why we need to clear the cache here.

For the manual cache, you could also just pop the value for this particular view from the cache instead. That would even be more efficient than clearing the entire cache.

Comment thread plugin/diagnostics.py Outdated
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 10, 2026

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit 84d2b45
🔍 Latest deploy log https://app.netlify.com/projects/sublime-lsp/deploys/69b072514ae3e90008e5ef7c
😎 Deploy Preview https://deploy-preview-2801--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

rchl and others added 2 commits March 10, 2026 20:30
Co-authored-by: jwortmann <jwortmann@outlook.com>
Comment thread plugin/diagnostics.py Outdated
@rchl rchl merged commit 15df98a into main Mar 11, 2026
8 checks passed
@rchl rchl deleted the fix/session-gc branch March 11, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants