Skip to content

feat: add dispose method to the client - #206

Merged
Dadadah merged 13 commits into
stoatchat:mainfrom
Arsabutispik:feat/client-dispose
Nov 22, 2026
Merged

Dadadah merged 13 commits into
stoatchat:mainfrom
Arsabutispik:feat/client-dispose

Conversation

@Arsabutispik

Copy link
Copy Markdown
Member

Adds Client.dispose()

Adds a way to fully tear down a Client so it can be garbage collected. Needed by for-web to fix a memory leak on logout and account switching (stoatchat/for-web#1803).

Changes:

  • Client.dispose(): cancels pending reconnects, removes all listeners, closes the events socket, clears channel timers, resets ready, entitlements and viewAs, then empties all collections. Safe to call more than once.
  • Client.disposed getter; connect() does nothing after disposal
  • logout() now always disposes, even if the logout request fails
  • Channel._clearTimers() (internal): clears typing, ack and slowmode timers
  • StoreCollection._clear() (internal): drops every object in a collection

Collections are cleared on the next tick, so UI that's still being torn down doesn't see empty data. If something outside the library still references a disposed client, it only holds an empty object, not the whole account's data.

Signed-off-by: İspik <ispik@ispik.dev>
@Pecacheu

Copy link
Copy Markdown
Contributor

Nice, this should definitely simplify the teardown process in for-web

Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
@Dadadah
Dadadah merged commit 869f60b into stoatchat:main Nov 22, 2026
4 checks passed
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.

3 participants