Skip to content

Memory leak: SDK event listeners never unsubscribed in App component #8258

Closed

Description

@sauerdaniel

Problem

The TUI App component subscribes to 6 SDK events but never unsubscribes from them:

  • TuiEvent.CommandExecute
  • TuiEvent.ToastShow
  • TuiEvent.SessionSelect
  • SessionApi.Event.Deleted
  • SessionApi.Event.Error
  • Installation.Event.UpdateAvailable

The sdk.event.on() method returns an unsubscribe function that is being ignored.

Code Location

packages/opencode/src/cli/cmd/tui/app.tsx - lines 557-616

Impact

  • Event listeners accumulate over component lifecycle
  • Closures retain references preventing garbage collection
  • Memory growth in long-running sessions
  • Potential duplicate event handling

Relates to #5363

Expected Behavior

Event listeners should be stored and unsubscribed in onCleanup:

const unsubs: (() => void)[] = []

unsubs.push(sdk.event.on(TuiEvent.CommandExecute.type, (evt) => {
  command.trigger(evt.properties.command)
}))

// ... other listeners

onCleanup(() => {
  unsubs.forEach((unsub) => unsub())
})

Activity

  1. github-actions commented on Jan 13, 2026

    @github-actions
    Contributor

    This issue might be part of a series of related memory leaks in the TUI. Please check:

    All three are part of #3013 (general memory issues). You may want to coordinate fixes across these related issues to address the broader memory leak problem systematically.

  2. added
    perfIndicates a performance issue or need for optimization
    on Jan 13, 2026
  3. github-actions commented on Mar 27, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions