Skip to content

Memory leak #9151

Closed
Closed

Description

@amat27

Description

more than 30Gig memory used after coding for about a morning. windows 11. using copilot provider

Plugins

none

OpenCode version

1.1.21

Steps to reproduce

coding work for half a day

Screenshot and/or share link

Image

Operating System

windows 11

Terminal

windows terminal

Activity

  1. github-actions commented on Jan 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. LIHUA919 commented on Jan 18, 2026

    @LIHUA919

    Based on my analysis of the recent memory leak fixes, here are the root causes:

    Root Causes

    1. TUI Footer Timeout Leak (#8255)

    The footer component creates recursive timeouts but only cleans up the last one:

    // Before (leak):
    let timeout = setTimeout(() => tick(), 10000)
    onCleanup(() => clearTimeout(timeout))  // Only clears last timeout
    
    // After (fixed):
    const timeouts = []
    timeouts.push(setTimeout(() => tick(), 10000))
    onCleanup(() => timeouts.forEach(clearTimeout))  // Clears all

    Hundreds of uncleaned timers accumulate over time.

    2. MCP Client Not Closed (#8253)

    When reinitializing MCP clients, the old one was overwritten without closing:

    // Before (leak):
    s.clients[name] = result.mcpClient  // Old client still active!
    
    // After (fixed):
    await existingClient?.close()
    s.clients[name] = result.mcpClient

    This is especially critical for Copilot users since it uses the MCP protocol.

    3. State Instance Not Removed from Map (#8252)

    // Before (leak):
    entries.clear()  // But recordsByKey still holds reference
    
    // After (fixed):
    entries.clear()
    recordsByKey.delete(key)  // Actually remove the reference

    Common Pattern

    All three issues stem from the same problem: creating new resources without properly tracking/cleaning up old ones.

    Recommendation

    1. Update to the latest version - These fixes are very recent (merged Jan 13-14)
    2. If the issue persists, please export your session to help identify remaining leaks:
      opencode export > session.json
    3. The MCP client leak (fix(mcp): close existing client before reassignment to prevent leaks #8253) is particularly relevant for Copilot users - make sure you have this fix

    Related Fixes

  3. kryptobaseddev commented on Feb 22, 2026

    @kryptobaseddev

    The 30 GB growth after a morning of coding matches what I found in the event-reducer. The message.part.delta handler in event-reducer.ts concatenates every incoming delta to a string per part field with no size limit — (existing ?? "") + props.delta. In a long session with lots of tool output, these strings grow into the hundreds of MB each and are never trimmed.

    Fixed in #14650 by capping each part field at 1 MB (drops oldest bytes on overflow). The PR also fixes the second major driver: subagent sessions are never deallocated after their task completes, so each one retains its full message history, tool buffers, and event listeners in memory permanently.

    Between those two fixes plus 8 other leak sources addressed in the same PR, a 2.5-hour test session with continuous subagent and tool activity stabilized at ~2,500 MB RSS instead of growing unbounded.

    Some of the leaks from this issue were fixed in v1.2.10 (footer timeout, SSE reconnect, AbortController), but the delta accumulation and subagent cleanup were still open on the current dev branch.

  4. g4challenge commented on Feb 24, 2026

    @g4challenge

    same behavior on my mac - especially when using long web sessions - up to 68gb ram usage. session ran 2 days.

  5. thdxr commented on Apr 2, 2026

    @thdxr
    Member

    Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingperfIndicates a performance issue or need for optimizationwindows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions