Skip to content

Memory leak: Instance disposal doesn't clean up plugins or cached resources #9157

Closed

Description

@sauerdaniel

Problem

When Instance.dispose() is called, several resources are not properly cleaned up:

1. Plugins Not Disposed

Plugins may hold resources (connections, file handles, caches) that need cleanup, but there's no disposal hook in the Hooks interface:

interface Hooks {
  // No dispose() method exists
}

2. Cached Instances Not Disposed

The instance cache uses a standard Map without disposal hooks. When instances are evicted (due to memory pressure or explicit removal), their state is not properly cleaned up.

3. No Bootstrap Cleanup

When the process exits, plugins are not given a chance to clean up their resources.

Code Locations

  • packages/plugin/src/index.ts - Hooks interface
  • packages/opencode/src/plugin/index.ts - Plugin loading
  • packages/opencode/src/project/instance.ts - Instance cache
  • packages/opencode/src/project/bootstrap.ts - Bootstrap process

Impact

  • Plugin resources leak on instance disposal
  • Cache eviction doesn't trigger cleanup
  • Process exit leaves orphaned resources

Relates to #5363
Depends on #9140 (LRU cache utility needed for onEvict callback)

Expected Behavior

  • Plugins should have a dispose() hook
  • Cache eviction should trigger disposal
  • Bootstrap should clean up plugins on exit

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Jan 17, 2026
  2. github-actions commented on Jan 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate or closely related to other memory leak issues in the repository. Please check:

    These issues appear to be related components of a larger memory management problem (#5363). They may be addressed separately or as part of a broader effort to eliminate memory leaks.

  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