Skip to content

fix: memory leak on logout and account switch - #1808

Draft
Arsabutispik wants to merge 1 commit into
mainfrom
fix/memory-leak
Draft

Arsabutispik wants to merge 1 commit into
mainfrom
fix/memory-leak

Conversation

@Arsabutispik

@Arsabutispik Arsabutispik commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fix memory leak on logout/account switch
Fixes #1083

Waiting on stoatchat/javascript-client-sdk#206

Logging out and back in (or switching accounts) kept the previous Client alive, so RAM grew with every cycle.

Causes found (via Chromium heap snapshots and Firefox GC/CC logs):

  • CodeMirror / ProseMirror editors were never destroyed, so their window listeners kept the whole old UI (and its client) alive
  • Solid <For> snapshots of floatingElements kept unregistered entries (and their closures) alive
  • The browser selection and focused element pointed at the detached logout button
  • Client teardown only happened after the async logout request finished

Changes:

  • Destroy editor views on cleanup
  • Empty floating entries when they unregister
  • Clear selection and focus when disposing a client
  • Use the new Client.dispose() from stoat.js (sync teardown, clears collections)
  • Remove listeners from the client they were added to (Messages, NotificationsWorker, SyncWorker)
  • Clear the query cache when the client changes
  • Guard client().user reads during account switches

How was this PR tested?

  • 3x add account -> back -> log in, then forced GC. Only the current client stays alive in both Firefox and Chromium.

Screenshots & Screencasts (if appropriate)

Checklist:

  • I have carefully read the contributing guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR
  • I have confirmed that any new dependencies are strictly necessary
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code

Please declare, if any, LLM usage involved in creating this PR

No AI was used

Signed-off-by: İspik <ispik@ispik.dev>
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.

Member list UI shows scrollbar carats even when there is no scrolling

1 participant