Repository navigation
Description
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)
externalandarrayBuffersare negligible — this is purely V8 JS string retentionHeapProfiler.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
- Open VS Code with 2 workspaces (one with ~1000 files)
- Open integrated terminals, run
tmuxinside them (tmux with status bar enabled) - Leave VS Code running for 30-60 minutes
- 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
.heapsnapshotfile) - Memory growth CSV with V8 inspector data available on request
- 99 Crashpad
.dmpfiles 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
anthonykim1 commentedon Apr 2, 2026
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?belltailjp commentedon May 6, 2026
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-extensionsorstart extension bisectyet.Phenomenon
VSCode suddenly and silently crushes after several hours or a few days of use.
Environment
10c8e557, 2026-04-22) and 1.118.1, 1.119.0; Electron 39.8.7tmuxCrash data
All 38 Crashpad dumps emitted by VS Code crashes carry
electron.v8-oom.is_heap_oomandp out of memory.25 of those dumps embed a GC log block ending with back-to-back zero-reclaim mark-compacts.
Memory growth profile (V8 inspector data, got 936 samples at 15s intervals)
Single PID and single
process.titleacross all 936 samples (234.9 min).The heapUsed delta +3809 MB (≈ 16 MB/min average), with
arrayBuffersandexternalnegligible, 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
heapUsedfirst crossed 3200 MB, which is approx 47 minutes before the crash.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).
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:--[element:5](Node / Environment)--[internal:principal_realm](Node / PrincipalRealm)--[internal:timers_callback_function](closure: processTimers)--[internal:context, internal:previous](system / Context)--[context:timerListMap](Object)--[element:6000](TimersList)--[property:_idlePrev](Timeout)setTimeout--[property:_onTimeout](closure)--[internal:context, context:this](object:bc)--[property:_onProcessData](object:b)--[property:_listeners](object:ka)--[property:value](closure)--[internal:context, context:ue](Array)--[element:N](object: Object)--[property:event](ANSI 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._onProcessData)Emitter<{ id: number; event: ... }>)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 byEvent.bufferviaProxyChannel.fromServiceinelectron-main/app.ts:It seems there already is
Dev-only leak detectionmechanism 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
belltailjp commentedon May 6, 2026
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
Launch a fresh VSCode:
Run a simple script that emits dense PTY control characters in the integrated terminal:
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
belltailjp commentedon Jul 1, 2026
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)
jacobjove commentedon Jul 1, 2026
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 severalclaudeCLI 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 undisposedEmitterlistener: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 inout/main.json 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: falsealso 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.
Fix main process OOM from unconsumed buffered pty host service events (…
Fix main process OOM from unconsumed buffered pty host service events (…