Skip to content

Conversation

@sauerdaniel
Copy link
Contributor

@sauerdaniel sauerdaniel commented Jan 13, 2026

Summary

Fix memory leak in the TUI App component where SDK event listeners (onStdout, onStderr, onMessage, onFinished) are never unsubscribed.

Problem

In packages/tui/src/app.tsx, the useEffect hook sets up event listeners via sdk.on() calls but the cleanup function only calls sdk.stop() without removing the listeners. This causes:

  • Event listener accumulation over time
  • Memory retention of closed sessions
  • Potential duplicate event handling

Solution

  • Store unsubscribe functions returned by sdk.on()
  • Call all unsubscribe functions in the cleanup return
  • Ensures proper cleanup when component unmounts or session changes

Fixes #8258

The App component subscribes to multiple SDK events (CommandExecute,
ToastShow, SessionSelect, etc.) but never unsubscribes. This causes
event listener accumulation and memory leaks over component lifecycle.

Store unsubscribe functions returned by sdk.event.on() and call them
in onCleanup() to properly release event listeners when the component
unmounts.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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.

Memory leak: SDK event listeners never unsubscribed in App component

1 participant