"Ineffective mark-compacts near heap limit": why your coding CLI dies in a long session
Back to the blog
Articletroubleshootingdev toolsverboo codeagente de programaçãogemini cli

"Ineffective mark-compacts near heap limit": why your coding CLI dies in a long session

MafraNovember 24, 20266 min read

You leave the coding agent running for hours, come back for the result, and find this in the terminal:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Aborted (core dumped)

The process died, the session went with it, and the last hour of work is gone. This error is not about the model, the quota, or the network. It is the JavaScript engine behind your terminal, V8, hitting the memory ceiling it had to work with. This guide explains what the message means, how to confirm that is what happened, and the command that fixes it on the spot, with a real case documented in the Gemini CLI repository on 2026-11-18.

Flowchart: heap out of memory in the CLI. If it died at session end, the heap filled up; if it was a spike, raise the ceiling with NODE_OPTIONS; if it grows nonstop, it is a leak and the path is the snapshot. The branch shows one session per task.
From crash to diagnosis: a full heap, a memory spike, or a leak each need a different fix.

What does "Ineffective mark-compacts near heap limit" mean?

It means V8's garbage collector tried to free memory and barely managed, because almost everything in memory was still in use. The "heap" is the region where JavaScript keeps live objects. "Mark-compact" is the collector stage that finds what is still referenced and rearranges the rest. When that stage runs near the limit and reclaims very little, V8 has nowhere to grow and aborts the process.

On a newer V8 the same condition shows up with different wording, and both lead to the same place:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

The confusing part: the message says "ineffective", as if the collector had failed. It did not. It ran and concluded the memory was genuinely in use. The problem is not the collector, it is how many objects stay alive at the same time.

Why does this happen in a long CLI session?

Because pruning the conversation context does not give memory back to the process. A coding CLI does two different things: it keeps the context window that goes to the model, and it keeps the Node process heap. When the CLI summarizes or drops old messages to fit the model window, it is trimming what gets sent, not necessarily what stays allocated in memory. The heap can grow even with a "healthy" context.

The documented case shows the gap clearly. In Gemini CLI issue #30352, the session ran about 20 hours and processed 182.4 million tokens. At crash time the status bar read 32% context used and 3.32 GB resident memory (RSS), yet V8 aborted at a 4,099.7 MB heap limit. Collection reclaimed only about 23.6 MB. In other words, more than 99% of objects were live and could not be freed. It was not piled-up garbage: it was retained state.

SignalWhat it measuresWhat it tells you
Context used (%)How full the model window isConversation health, not memory health
RSS (resident memory)Physical memory the process occupiesCan sit below or above the heap
heap_size_limitThe heap ceiling V8 acceptsThe process aborts at this number
heapUsedLive memory inside the heapRising and never falling = leak

That is why watching RSS alone misleads. A monitor that compares RSS against a fixed threshold may never fire, while the heap, which is what actually overflows, fills in silence. A technical comment on the issue points to exactly this: the warning was tied to a 7 GB ceiling that would never be reached on a 4 GB heap.

How do I confirm it is the heap ceiling?

First, check which heap ceiling your Node sees on this machine:

node -e "console.log((require('v8').getHeapStatistics().heap_size_limit/1048576).toFixed(0) + ' MB')"

The number that prints is the limit in megabytes. If it is around 4,000 MB, you are on the default ceiling and a long session can reach it. Second, watch the process during the session. RSS in KB, read every few minutes, shows the curve:

ps -o rss= -p <PID>

If RSS climbs without stopping and never falls, even when idle, that is a sign of memory retention, not a temporary spike. If it rises and falls, the collector is keeping up and the crash was probably a spike, not a leak.

How do I fix it now, with one command?

Raise the heap ceiling for the next session. The --max-old-space-size option sets the maximum size, in MiB, of the heap's old generation (the main JavaScript memory), and it is accepted inside NODE_OPTIONS. For a CLI installed as gemini, claude, or verboo, the format is the same:

NODE_OPTIONS=--max-old-space-size=8192 gemini

Replace gemini with your CLI's command. The value 8192 is 8 GB; adjust to your machine's memory, leaving headroom for the system. On Windows, the PowerShell equivalent:

$env:NODE_OPTIONS="--max-old-space-size=8192"; gemini

This does not fix a leak, but it gives the session room to finish the task. If the goal is to find the cause rather than just postpone the crash, ask V8 for a memory snapshot shortly before the limit:

NODE_OPTIONS="--max-old-space-size=4096 --heapsnapshot-near-heap-limit=1" gemini

The --heapsnapshot-near-heap-limit option writes a .heapsnapshot file when the process nears the ceiling. That file opens in the Memory tab of Chrome DevTools and shows exactly which objects are holding the memory. It is what turns "the CLI died" into "the CLI died because of this state".

Does raising the limit fix it for good?

It depends on whether memory grows in a spike or a leak. If it was a spike (one big task, one huge file), raising the ceiling fixes it. If the heap grows without stopping over hours, as in the 99% live-object case, a bigger ceiling only postpones the crash: you trade an abort at 4 GB for an abort at 8 GB, later. In that scenario, file the issue with the snapshot and, until the fix lands, restart the process per task instead of keeping a 20-hour session alive.

Worth noting what is not the cause either: Codex CLI is written in Rust, so it does not go through V8 and does not emit this message. It is typical of CLIs built on Node, such as Gemini CLI, [CC], and Verboo Code.

How do I keep it from happening again?

  • One long task per process. Close and reopen the CLI between big tasks instead of piling a whole day into a single session.
  • Update the CLI. This kind of retention usually turns into a version fix; running the latest release is the shortest path.
  • Watch the heap, not just RSS. The number that aborts is the heap.
  • When it happens, capture the snapshot before closing. Without it, the report becomes "it broke", and "it broke" does not become a fix.

If you use Verboo Code in the terminal, it also runs on Node, so the same NODE_OPTIONS=--max-old-space-size=8192 applies to long sessions. And because its plans run with unlimited tokens, letting the session work longer does not change the bill. Meet Verboo Code.

Enjoyed this article?
Share knowledge with your network.
// Read also

Related articles