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())
})