Skip to content

Multiple memory leaks cause unbounded RAM growth during extended TUI usage #16697

@binarydoubling

Description

@binarydoubling

Description

During extended usage, OpenCode exhibits unbounded memory growth from multiple independent sources. This has been independently reported and investigated by 20+ contributors, resulting in a massive wave of PRs that collectively address the full scope of the problem.

Scope of Memory Leaks

In-Memory Leaks (Runtime)

Category Source Impact PR(s)
TUI event listeners sdk.event.on() in app.tsx, session route, prompt — never unsubscribed Listeners accumulate on every navigation/re-render #16695, #8254, #9147
Unbounded Maps/Sets LSP diagnostics, Bus subscriptions, RPC listeners — grow without eviction Monotonic memory growth over session lifetime #16695, #12259
Timer/interval leaks Models refresh interval, leader timeout, state disposal timeout — never cleared Closures + captured state retained indefinitely #16695, #9148
Session data retention Sync store never frees previous session's messages/parts/diffs on switch Memory scales with number of sessions visited #16695, #10392
Plugin subscriber stacking Bus.subscribeAll() called without storing unsubscribe handle Each init() stacks another permanent wildcard subscriber #16346
Message array retention Full msgs array stays alive during processor.process() Large arrays pinned in memory unnecessarily #16346
Subagent deallocation Subagent sessions never deallocated after task completion GB-scale growth in long-running sessions #14650, #15435
Event-reducer accumulation Message delta strings accumulate without cap Unbounded string growth #14650
SSE stream leaks SSE connections not properly cleaned up on disconnect Stale connections hold memory #15646, #9146
Process/Bus cleanup Child processes and Bus subscriptions not cleaned on instance disposal Resources retained after they're needed #15646, #13186, #9149
Subscription disposal No dispose functions for Bus subscriptions Permanent listeners on long-lived instances #7914, #7032
Tool output retention Tool output and attachments not cleared when pruning Dead data accumulates #7049
OAuth transport leaks MCP OAuth transports accumulate without timeout Abandoned flows hold memory #9145
LSP stderr buffering LSP server stderr not consumed, grows unbounded Memory growth per LSP server #16241
Zombie processes Missing cleanup handlers leave child processes running Process accumulation over time #13186, #15757
MCP server accumulation Idle MCP server instances never disposed Process count grows indefinitely #15326
Instance disposal No idle-timeout disposal in serve mode Instances live forever #16616

Database & Storage Leaks

Category Source Impact PR(s)
No data retention Sessions spanning 53+ days, never auto-cleaned DB grew to 1.99 GB #16730
auto_vacuum = OFF Deleted data never reclaims disk space SQLite file only grows #16730
Unbounded WAL No periodic WAL checkpoint WAL file grows indefinitely #16730
Oversized cache_size 64 MB fixed allocation Excessive for embedded tool #16730
Startup cleanup No maintenance/cleanup on startup Stale data persists across restarts #16628

Real-World Impact

All Related PRs

Over 20 open PRs addressing memory leaks, spanning January–March 2026:

Core memory leak fixes

PR Author Focus Files
#16695 @binarydoubling TUI listeners, Maps/Sets eviction, timers, session cleanup 16
#16730 @BYK SQLite config, database bloat, data retention
#16346 @GooseG17 Plugin subscriber stacking, msgs retention, LSP 5
#14650 @kryptobaseddev Subagent deallocation, event-reducer caps 14
#15646 @brendandebeasi SSE streams, Bus disposal, process cleanup 11
#15435 @tda1017 Consolidation of #14650 and #8953 24
#13594 @feelsodev 6 memory leaks for long-running sessions 6
#13186 @dzianisv Memory leaks and zombie processes 16
#10392 @ztripez Session handling memory leaks 15
#13514 @sebishogun Multiple memory leaks (with Windows test fixes) 1

Targeted fixes

PR Author Focus Files
#16616 @sjawhar Idle-timeout Instance disposal for serve mode 2
#16241 @dimaosipa LSP stderr unbounded growth 2
#16628 @jmylchreest Startup cleanup and maintenance system 6
#15326 @lytedev Dispose idle MCP server instances 2
#12259 @Stranmor TTL, LRU eviction, ring buffers 4
#9146 @sauerdaniel Session event stream leaks (ACP) 2
#9147 @sauerdaniel Event listener leaks in TUI 3
#9148 @sauerdaniel Timeout, interval, subscription cleanup 3
#9145 @sauerdaniel OAuth transport and process cleanup 2
#9149 @sauerdaniel Instance disposal chain for plugins/caches 6
#8254 @sauerdaniel SDK event listener cleanup on unmount 1
#7914 @hendem Subscription disposal functions 10
#7049 @hendem Tool output/attachment cleanup on prune 2

Monitoring & diagnostics

PR Author Focus Files
#13194 @goniz Memory usage monitoring/leak detection 6

Related Issues

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions