GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: cleanup SDK event listeners to prevent memory leaks by cloudwaddie-agent · Pull Request #14635 · anomalyco/opencode

Conversation

@cloudwaddie-agent

@cloudwaddie-agent cloudwaddie-agent commented Feb 22, 2026

Copy link
Copy Markdown

Summary

This PR fixes memory leaks caused by event listeners not being properly cleaned up when TUI components unmount.

Changes

app.tsx

  • Added onCleanup handler for 6 SDK event listeners:
    • TuiEvent.CommandExecute
    • TuiEvent.ToastShow
    • TuiEvent.SessionSelect
    • SessionApi.Event.Deleted
    • SessionApi.Event.Error
    • Installation.Event.UpdateAvailable

session/index.tsx

  • Added onCleanup for message.part.updated event listener

prompt/index.tsx

  • Added onCleanup for TuiEvent.PromptAppend event listener

Why This Matters

Previously, these event listeners were registered in component render but never unregistered. If the TUI remounts these components, duplicate listeners accumulate. Over time with multiple sessions/remounts, this causes memory growth leading to the 98% memory usage reported in the issue.

Testing

To verify the fix:

  1. Build the project: cd packages/opencode && bun run build
  2. Run opencode TUI
  3. Monitor memory with htop or Activity Monitor
  4. Create and switch between multiple sessions
  5. Read files in different sessions
  6. Memory should now stay stable instead of growing

You can also use the built-in heap snapshot feature:

  • Run opencode.status command in TUI
  • Select "Write heap snapshot"
  • Compare snapshots to verify listener count decreases on component unmount

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cloudwaddie-agent
fix: cleanup SDK event listeners to prevent memory leaks
731b3fd
This commit fixes memory leaks caused by event listeners not being properly cleaned up when TUI components unmount.

Changes:
- app.tsx: Added onCleanup for 6 SDK event listeners (CommandExecute, ToastShow, SessionSelect, SessionDeleted, SessionError, UpdateAvailable)
- session/index.tsx: Added onCleanup for message.part.updated event listener
- prompt/index.tsx: Added onCleanup for PromptAppend event listener

These fixes ensure that event subscriptions are properly unsubscribed when components unmount, preventing memory growth over time.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 22, 2026
@github-actions

github-actions Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the needs:issue label Feb 22, 2026
@github-actions

github-actions Bot commented Feb 22, 2026

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cloudwaddie-agent cloudwaddie-agent mentioned this pull request Feb 22, 2026
feat: compact and other improvements #1
Merged
@github-actions

github-actions Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

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

Based on my search, I found several potentially related PRs:

Potential Duplicates/Related PRs:

  1. fix(tui): clean up SDK event listeners on unmount #8254 - fix(tui): clean up SDK event listeners on unmount

    • Directly addresses the same issue of cleaning up SDK event listeners in TUI components
  2. fix(memory): Fix event listener leaks in TUI and Slack bot #9147 - fix(memory): Fix event listener leaks in TUI and Slack bot

    • Explicitly fixes event listener memory leaks in TUI and other components
  3. fix(memory): Fix timeout, interval, and subscription cleanup #9148 - fix(memory): Fix timeout, interval, and subscription cleanup

    • Related memory leak fixes for similar cleanup patterns
  4. fix(opencode): memory leaks in session handling #10392 - fix(opencode): memory leaks in session handling

    • Addresses memory leaks in session handling, which overlaps with the session-related listener cleanup in PR fix: cleanup SDK event listeners to prevent memory leaks #14635
  5. fix(core): add dispose functions to prevent subscription memory leaks #7032 - fix(core): add dispose functions to prevent subscription memory leaks

    • Similar pattern of adding disposal/cleanup functions to prevent memory leaks
  6. fix: resolve memory leaks and zombie processes from missing cleanup handlers #13186 - fix: resolve memory leaks and zombie processes from missing cleanup handlers

    • Another PR addressing missing cleanup handlers causing memory leaks

Most likely duplicates: PRs #8254 and #9147 appear to be addressing the exact same issue of cleaning up SDK event listeners in TUI components.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cloudwaddie-agent cloudwaddie-agent mentioned this pull request Feb 22, 2026
Memory leak #9385
Closed
@github-actions

github-actions Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Feb 22, 2026
@kryptobaseddev kryptobaseddev mentioned this pull request Feb 22, 2026
fix: resolve memory leak issues across multiple subsystems #14650
Closed
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@cloudwaddie-agent
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.