Skip to content

Main process OOM: terminal PTY output strings accumulate unboundedly in V8 heap (~37 MB/min) #307156

Closed as duplicate

Description

@dragonkid

Bug Description

The VS Code main (browser) process accumulates terminal PTY output as V8 string objects that are never garbage-collected, leading to unbounded heap growth and eventual OOM crash (Reached heap limit). The leak is specifically caused by ANSI escape sequences from terminal output (cursor positioning, colors, box-drawing characters) being retained as interned strings in the V8 heap.

Evidence

Heap snapshot analysis (taken at RSS = 950 MB, ~10 min after launch)

Metric Value
Total V8 heap 865 MB
ANSI terminal string objects 30,322 objects, 842 MB (97.3% of heap)
Non-terminal heap usage ~23 MB

The leaked strings are terminal escape sequences like:

\x1b[1;177H\x1b[38;5;33m│\x1b[2;177H│\x1b[3;177H│...

These contain cursor positioning (\x1b[1;177H), colors (\x1b[38;5;33m), and box-drawing characters (│) — consistent with tmux status bar and pane border rendering.

Memory growth profile (V8 inspector data, 20 samples at 30s intervals)

Time     | RSS    | V8 heapUsed | external | arrayBuffers
21:42:37 |  740 M |       510 M |      4 M |          0 M
21:47:08 |  708 M |       664 M |      6 M |          0 M
21:52:09 |  950 M |       857 M |     15 M |          0 M
  • V8 heapUsed grows at ~37 MB/min (RSS tracks heapUsed closely)
  • external and arrayBuffers are negligible — this is purely V8 JS string retention
  • HeapProfiler.collectGarbage() does not reclaim these strings

Crash data

  • 99 OOM crash dumps over 30 days (median interval: 4.2 hours)
  • All crashes are in the main/browser process (not renderer or extension host)
  • Crash dump GC log: Mark-Compact (reduce) 3642.0 (4002.9) -> 3642.0 (4002.9) MB — GC cannot reclaim anything at crash time
  • Crash signals: electron.v8-oom.is_heap_oom, Reached heap limit

Control experiments

Configuration Growth rate Notes
--disable-extensions ~0 MB/min Stable at 233 MB for 10+ min
All extensions enabled ~37-59 MB/min Crashes in ~1 hour
Extensions enabled, no tmux in terminal TBD

Steps to Reproduce

  1. Open VS Code with 2 workspaces (one with ~1000 files)
  2. Open integrated terminals, run tmux inside them (tmux with status bar enabled)
  3. Leave VS Code running for 30-60 minutes
  4. Observe main process RSS growing continuously until OOM crash

Root Cause Hypothesis

Terminal PTY output data (ANSI escape sequences) is being retained as V8 string objects in the main process heap without bounds. Possible locations:

  • IPC message serialization between pty-host and main process retaining string references
  • Terminal scrollback buffer data being forwarded through the main process and not released
  • String interning in the serialization layer causing permanent retention

The strings appear to be full terminal screen redraws from tmux (cursor positioning for every cell + color codes), suggesting each tmux status bar refresh or pane redraw generates a large string that gets permanently retained.

Environment

  • VS Code: 1.114.0 (e7fb5e9), arm64
  • OS: macOS 26.3 (Darwin 25.3.0), Apple M4 Pro, 48 GB RAM
  • Electron: 39.x (Chromium 142.0.7444.265)
  • tmux: 3.6a
  • Extensions: 49 installed (leak occurs regardless of which extensions are enabled, as long as extensions are not fully disabled; tmux terminal output is the data source)

Diagnostic files

  • Heap snapshot available on request (28 MB .heapsnapshot file)
  • Memory growth CSV with V8 inspector data available on request
  • 99 Crashpad .dmp files from the past 30 days

Workaround

Avoid running tmux (or other programs with heavy ANSI output) inside VS Code's integrated terminal. Use an external terminal emulator for tmux sessions instead.

Activity

  1. anthonykim1 commented on Apr 2, 2026

    @anthonykim1
    Contributor

    DragonKid (@dragonkid) Thanks for the issue.
    Interesting how the growth rate is 0 for disabled extension. I wonder if this is extension problem.

    Can you open command palette and run start extension bisect ?

  2. added
    bug
    terminal-process
    on Apr 2, 2026
  3. belltailjp commented on May 6, 2026

    @belltailjp

    I've been apparently hitting the same crash, so let me share heap snapshot analysis along with a few additional investigation. Please be noted that my analysis heavily relies on advice from Claude Code as I am not familiar with the codebase.
    # Reproducing the crash takes hours of real workload, so I haven't been able to try --disable-extensions or start extension bisect yet.

    Phenomenon

    VSCode suddenly and silently crushes after several hours or a few days of use.

    Environment

    • VS Code 1.117.0 (10c8e557, 2026-04-22) and 1.118.1, 1.119.0; Electron 39.8.7
    • macOS 26.4, Apple M2 Pro, 32 GB
    • Integrated terminal: long-lived tmux
      • Claude Code CLI running inside as a long-running interactive process inside

    Crash data

    All 38 Crashpad dumps emitted by VS Code crashes carry electron.v8-oom.is_heap_oom and p out of memory.
    25 of those dumps embed a GC log block ending with back-to-back zero-reclaim mark-compacts.

    Mark-Compact (reduce) 3955.5 (4000.4) -> 3955.5 (4000.4) MB ... last resort; GC in old space requested
    Mark-Compact (reduce) 3955.5 (4000.4) -> 3955.5 (4000.4) MB ... last resort; GC in old space requested
    

    Memory growth profile (V8 inspector data, got 936 samples at 15s intervals)

    Single PID and single process.title across all 936 samples (234.9 min).

    time (UTC) heapUsed RSS external arrayBuffers
    09:09:33 145 MB 316 MB 5 MB 0
    12:06:06 3020 MB 322 MB 5 MB 0
    13:04:30 (just before crash) 3954 MB 4308 MB 4 MB 0

    The heapUsed delta +3809 MB (≈ 16 MB/min average), with arrayBuffers and external negligible, which is consistent to the original issue report.
    heapUsed climbed constantly while RSS spiked sharply just before the crash (316 → 252 → 285 → 322 → 4308 MB).

    Heap snapshot analysis

    To find what is filling the heap, I took a snapshot of the same main (browser) process when heapUsed first crossed 3200 MB, which is approx 47 minutes before the crash.

    node type count self_size % of snapshot
    string 413,345 3,173 MB 99.31%
    object 455,734 9 MB 0.29%
    code 86,045 6 MB 0.18%

    Actually I found out that string nodes containing an ANSI escape sequence (CSI introducer \x1b[) account for 98.98% of the heap.
    Some of these grow to KBs-scale, including color / cursor-positioning / erase-line escapes as well as terminal output text. Also many come from Claude Code CLI in particular, but seemingly not limited to it (any control sequences would have piled up).

    m\x1b[38;5;246m(10s · ↓\x1b[39m \x1b[38;5;246m414 tokens)\x1b[39m   # Claude Code: status display (~2,767 strings)
    \x1b[4;6H\x1b[1mBash\x1b(B\x1b[m…                                    # Claude Code: Bash tool call (12,508)
    \x1b[6;6H\x1b[1mRead\x1b(B\x1b[m(…)                                  # Claude Code: Read tool call (10,899)
    \x1b[1mExplore\x1b(B\x1b[m(…)                                        # Claude Code: Explore tool call (8,007)
    

    Nearly all of the heap is terminal output retained rather than released until the crash.

    Retainer chain

    To identify the retention path, I dumped the object graph (retainer chain) up to a GC root from instances of the string groups above along strong edges only (no weak/shortcut).
    354,393 of 354,399 ANSI strings in the snapshot (≈100%, 3,162 MB / 3,163 MB) were retained via the same Emitter (b) path:

    object note
    synthetic root (id 0) GC root entry
    --[element:5] (Node / Environment)
    --[internal:principal_realm] (Node / PrincipalRealm)
    --[internal:timers_callback_function] (closure: processTimers) Node timer scheduler
    --[internal:context, internal:previous] (system / Context)
    --[context:timerListMap] (Object)
    --[element:6000] (TimersList) pending timers list
    --[property:_idlePrev] (Timeout) unfired setTimeout
    --[property:_onTimeout] (closure) the setTimeout callback
    --[internal:context, context:this] (object: bc) service instance
    --[property:_onProcessData] (object: b) Emitter
    --[property:_listeners] (object: ka) listener entry
    --[property:value] (closure) listener callback
    --[internal:context, context:ue] (Array) growing buffer
    --[element:N] (object: Object) one queued event (N up to 305,245 observed)
    --[property:event] (ANSI string) the retained string

    When I dump the same retainer chain from a fresh VSCode session, the Array (ue) is already at ~76k entries and still growing — suggesting this Array is the leak point.

    Implementation hypothesis

    To identify the part holding the Array (ue) above, I compared it against the VS Code 1.117.0 implementation on the following points.

    1. matches unminified property symbols (_onProcessData)
    2. matches event payload type (Emitter<{ id: number; event: ... }>)
    3. matches closure shape inside the chain (array push + setTimeout-driven flush)

    This is analysis on a minified-build dump, so it is not definitive, but the chain lines up with PtyHostService._onProcessData (Emitter<{ id: number; event: IProcessDataEvent | string }>) being wrapped by Event.buffer via ProxyChannel.fromService in electron-main/app.ts:

    // event.ts: Event.buffer (L515-L604)
    export function buffer<T>(event: Event<T>, debugName: string, flushAfterTimeout = false, _buffer: T[] = [], disposable?: DisposableStore): Event<T> {
      let buffer: T[] | null = _buffer.slice();           // ← Array (ue) in the chain
      // ... (dev-only leak warning timer setup)
      let listener: IDisposable | null = event(e => {
        if (buffer) {
          buffer.push(e);                             // ← grows element:N → Object.event
          // ... (leak count threshold warning)
        }
        // ... (else: post-flush passthrough)
      });
      // ... (const flush definition: drains buffer, then sets buffer = null)
      const emitter = new Emitter<T>({
        // ... (onWillAddFirstListener)
        onDidAddFirstListener() {
          if (buffer) {
            if (flushAfterTimeout) {
              setTimeout(flush);                  // ← Timeout._onTimeout, pending if drain never fires
            }
            // ... (else: synchronous flush)
          }
        },
        // ... (onDidRemoveLastListener)
      });
      // ...
      return emitter.event;
    }

    It seems there already is Dev-only leak detection mechanism for the same issue while it only works with _isBufferLeakWarningEnabled.

    Relevant source (VS Code 1.117.0):
    https://github.com/microsoft/vscode/blob/1.117.0/src/vs/platform/terminal/node/ptyHostService.ts#L80
    https://github.com/microsoft/vscode/blob/1.117.0/src/vs/code/electron-main/app.ts#L1349
    https://github.com/microsoft/vscode/blob/1.117.0/src/vs/base/parts/ipc/common/ipc.ts#L1109-L1119
    https://github.com/microsoft/vscode/blob/1.117.0/src/vs/base/common/event.ts#L515-L601

  4. belltailjp commented on May 6, 2026

    @belltailjp

    I hypothesize that extensions actually have nothing to do with the leakage, assuming it occurs in the path I reported above. I set up a minimal reproduction (like an accelerated durability test) and conducted an ablation study.

    The conclusion is that the leak reproduces by heavy-duty PTY escape sequence outputs even with a fresh VSCode session without extension.

    Reproduction

    1. Launch a fresh VSCode:

      code --new-window --disable-extensions \
           --user-data-dir /tmp/fresh-vscode-data \
           --extensions-dir /tmp/fresh-vscode-ext
      
    2. Run a simple script that emits dense PTY control characters in the integrated terminal:

      R=$(tput lines); C=$(tput cols)
      while :; do
        # paint random-position random-color cells
        # formats are just loop-unrolled 10x to reach up to ~100 MB/min output for very quick reproduction
        printf '\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m\033[%d;%dH\033[38;5;%dm\033[48;5;%dm%d\033[0m' \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10)) \
          $((RANDOM%R+1)) $((RANDOM%C+1)) $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%10))
      done
    3. Leave it alone. No code edit, just keep the integrated terminal opened.

    While this runs, I monitored the VSCode main process's process.memoryUsage() via the V8 inspector and captured a heap snapshot just before crash.

    Observation

    • heapUsed grew monotonically from 15.6 MB to 3,915 MB in ~20 min (≈ 199 MB/min) until it crashes
      • 12x speed compared to my real workload (suggests that Code can crush in 20*12 = 240mins = 4 hours, which is reasonably close to my experience).
    • Heap grew at a steady ~200 MB/min — twice the script's raw output (~100 MB/min), suggesting the terminal output is mainly what is captured and retained
    • Every string object taking up the heap shares the identical retainer chain shape as my previous report
    • VSCode main process crashed near V8's ~4 GB limit
  5. belltailjp commented on Jul 1, 2026

    @belltailjp

    DragonKid (@dragonkid) Hi, are you still facing this VSCode OOM issue? If so, could you give the above reproduction a try and share us a result? (it does still happen to me with VSCode 1.126.0)

  6. jacobjove commented on Jul 1, 2026

    @jacobjove
    Contributor

    Confirming this on a second machine, with a retainer trace that may help pin the exact retaining reference.

    Environment: VS Code 1.126.0, macOS 26.5.1 (Darwin 25.5.0), Apple silicon (Mac16,7), 48 GB. Identical symptom: the main/browser process climbs to V8's ~4 GB old-space ceiling and OOM-aborts (OOM error in V8: Reached heap limit; Mark-Compact (reduce) 3932.3 (4003.0) -> 3932.3 (4003.0) MB ... last resort), driven by several claude CLI sessions running in tmux inside the integrated terminal. Growth ~76–128 MB/min under heavy multi-session load (higher than the ~37 MB/min above, roughly proportional to terminal-output volume).

    Retainer trace (the part I think is new). I captured a heap snapshot of the main process via CDP (SIGUSR1 → HeapProfiler) and walked the retaining path of the ANSI strings. They aren't loose or interned — they're held by a growing array behind an undisposed Emitter listener:

    (GC root)
      → Emitter ( _listeners )
        → closure → Context            (captured local, minified `fe`/`me`)
          → Array  [index 60531]        ← grows unbounded, ~1 entry per redraw
            → Object { event: "<ansi frame>" }
              → string "\x1b[H\x1b[38;5;208m──…tmux status bar…──"
    

    So each PTY data event is wrapped as { event: <string> } and pushed into an array captured by an emitter-listener closure in the main process; that array reached 60,531 entries in ~1 hour. Allocation sampling (HeapProfiler.startSampling) attributes ~470–630 MB (≈95% of the climb) to a single frame in out/main.js on the terminal/IPC receive path (onRawMessage / listen / fire).

    Corroborating the control experiment: disabling a single extension did not help — I tested anthropic.claude-code (which coincidentally held its own large but bounded blob); the leak continued unchanged. Consistent with "not any one extension." The only thing that stopped the climb was moving the tmux sessions to an external terminal. For the record, terminal.integrated.enablePersistentSessions: false also had no effect (measured post-reload: same array, same ~76 MB/min, OOM again) — a natural thing to try, so worth noting it isn't a workaround.

    Heap snapshots and the allocation profile available if useful.

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

Metadata

Metadata

Labels

bugconfirmation-pendingterminal-process

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions