HardwareHardware problems and fixes

OpenClaw "JavaScript heap out of memory": causes and fixes

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory is Node.js stopping OpenClaw because the JavaScript heap hit its ceiling. On a big machine it usually points at a bug or a very large workload; on a 1 or 2 GB board it usually means the machine is smaller than what the Gateway now needs. The fix depends on which of the two you have.

In short: If you run OpenClaw as a service, its own installer already sets the heap limit for you; raising it with NODE_OPTIONS is a workaround, not a cure. On a 1 or 2 GB Raspberry Pi the real fix is more memory: swap at the very least, and for an always-on host a board with 4 GB or more. On a large machine, update first: several heap crashes reported on GitHub were bugs fixed in a later release.

For OpenClaw on a board, the Raspberry Pi 5 with 4 or 8 GB: the rows the OpenClaw docs rate best.
Buy the Raspberry Pi 5 on Amazon
At a glance
The messageFATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Who sets the heapopenclaw gateway install, when no heap setting exists: 50% of capacity, 2048 MiB nominal floor
OpenClaw minimum (Pi page)1 GB RAM, 1 core, 500 MB disk, 64-bit OS; 2 GB+ recommended
Node advice for a 2 GiB machine--max-old-space-size=1536, to leave room and avoid swapping
Lean profile for small machinesproposed in issue #202373, open: not shipped

What the error means

Node.js runs OpenClaw on the V8 engine, which keeps most long-lived JavaScript objects in a region called the old space. The flag --max-old-space-size caps it. Node's documentation describes the behaviour near the cap: "As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory." When collection cannot free enough, the process aborts with the message above.

Two things follow. The crash is about the heap cap, not necessarily about free RAM: a machine with free memory can still hit a low cap. And the cap is not the whole process: OpenClaw's docs say "Old space is only part of V8's total heap, and neither is a limit on total process memory (RSS)." A Gateway can therefore be killed by the system for using too much memory overall, which is a different failure (on Docker, see exit code 137 and OOMKilled).

OpenClaw already sizes the heap when it installs the service

Most guides online tell you to add NODE_OPTIONS. Before you do, know what the project does itself. Its service docs: "For a managed Node Gateway without an existing heap setting, gateway install places --max-old-space-size in Node's launch arguments, before the entry script." The rule it applies:

RuleValue
Target50% of capacity
Nominal floor2048 MiB
Capthe greater of 8192 MiB or 25% of capacity
Final cap75% of capacity, which "can put small-host budgets below the nominal floor"

On a 1 GB board the arithmetic is the problem. Issue #200671 (a user report on a Raspberry Pi 4 with 1 GB, 511 MB of swap and an SD card, OpenClaw 2026.11.5) says it directly: "The 1 GB host is below the gateway's own 2048 MiB heap floor". No heap flag fixes a machine that has less memory than the heap the software is designed around.

On Linux, the same managed services and the official Docker image also default to MALLOC_ARENA_MAX=2 "to reduce glibc malloc arena fragmentation". If you wrote your own systemd unit or container command, you do not get either default: regenerating the service with openclaw gateway install is the documented path.

What users report on small boards

These are reports on OpenClaw's GitHub, by users and contributors, not statements from the maintainers and not our own measurements:

IssueMachineWhat it says
#45440 (closed)Raspberry Pi 4, about 2 GBHeap crash after the 2026.3.12 upgrade. A contributor called a lower heap flag "workaround, not a true fix"; closed against the 2026.3.13 release, which fixed a memory blow-up.
#200671 (closed)Raspberry Pi 4, 1 GBRestart loop under systemd; the host is below the 2048 MiB heap floor.
#157791 (open)ARM64, 3.7 GiB RAM, 2 GiB swapAbout 138 s startup and steady memory near 1.32 GiB RSS.
#169797 (open)single-CPU arm64 hostPeak memory from 706 MB to 1,815 or 1,938 MB between releases.
#202373 (open)proposalA "lean" profile for machines of about 2 GiB or less; idle RSS rose from 419 to 821 MiB between v2026.7.1 and main.

The trend is plain: the Gateway has grown, and a lean mode for small machines is only a proposal so far. Buying a board for OpenClaw today, plan for the current memory use, not for a future profile.

The workaround: set the heap flag yourself

For a Gateway you start by hand, OpenClaw's troubleshooting page gives this form, "on a host with sufficient capacity":

NODE_OPTIONS="--max-old-space-size=16384" openclaw gateway run

For a custom supervisor or a Docker command, the same page says to place the flag "immediately after node, before the OpenClaw entry script, or set NODE_OPTIONS in that process or container's launch environment." The value 16384 is the docs' example for a large host, not a number to copy onto a Pi. Node's own advice for a small machine: "On a machine with 2 GiB of memory, consider setting this to 1536 (1.5 GiB) to leave some memory for other uses and avoid swapping."

In issue #45440 a commenter put Environment="NODE_OPTIONS=--max-old-space-size=2048" in the systemd unit. That buys headroom on a large machine. On a 2 GB board it lets the heap claim nearly all the RAM, which pushes the rest of the system into swap: the crash may stop, and the board becomes slow instead.

The fix on a 1 or 2 GB board: memory

OpenClaw's Raspberry Pi page rates a Pi 4 with 2 GB "OK" with the note "Add swap", a 1 GB Pi 4 "Tight" ("Possible with swap, minimal config"), and the Pi 5 with 4 or 8 GB "Best". Its documented setup adds a 2 GB swap file, "important for 2 GB or less". Its out-of-memory checklist: verify swap with free -h, disable unused services with sudo systemctl disable cups bluetooth avahi-daemon, and use API models only.

Swap is a stopgap. It turns a crash into slowness, and on an SD card it adds writes to a medium the same page says to avoid ("Use a USB SSD, SD cards are slow and wear out"; more on SD card corruption). If the board is a Pi 4 with 1 or 2 GB, the page on OpenClaw on a Raspberry Pi 4 covers what still runs. For a new purchase, a Pi 5 with 8 GB (Raspberry Pi 5 on Amazon) is above the 2048 MiB floor with room for the system; our estimates for each agent are on how much RAM an agent needs.

What to buy

  • Raspberry Pi 5: take the 8 GB board for OpenClaw: above the Gateway's 2048 MiB heap floor with room left.
  • USB 3 SSD: for swap and the system: OpenClaw's Pi page says to use a USB SSD rather than an SD card.
  • Raspberry Pi SSD, M.2 2230: the NVMe route on a Pi 5, with the M.2 HAT+.
The machine for this setup: the Raspberry Pi 5.
Buy the Raspberry Pi 5 on Amazon

Shop links go through /go/ and open Amazon (amazon.fr in the EU and Switzerland, amazon.com elsewhere). As an Amazon Associate we earn from qualifying purchases. Your price does not change and no brand pays for a place on this page (disclosure). We write no price down: it moves, the shop shows today's.

Questions

Is NODE_OPTIONS=--max-old-space-size the fix for OpenClaw's heap error?
It is a workaround. OpenClaw's service installer already sets the flag when there is no existing heap setting. Raising it helps when the machine has spare RAM and the cap is the limit; on a 1 or 2 GB board it moves the problem into swap.
What heap size does OpenClaw use by default?
When gateway install writes the service, it targets 50% of capacity, with a nominal 2048 MiB floor, a cap of the greater of 8192 MiB or 25% of capacity, and a final 75% cap that can take small hosts below the floor.
Can OpenClaw run on a 1 GB Raspberry Pi?
OpenClaw's Pi page lists 1 GB as the minimum and rates a 1 GB Pi 4 as tight, possible with swap and a minimal config. A user report (issue #200671) notes such a host is below the Gateway's own 2048 MiB heap floor. For an always-on host, take 4 GB or more.
The error appears on a machine with plenty of RAM. Why?
Then the cause is usually the workload or a bug. Issue #186739 reports a heap exhaustion at cold start with 168 agents on an 11.4 GiB machine, and issue #45440 was closed by a release that fixed a memory blow-up. Update OpenClaw first, then raise the heap flag if the host has the room.
Does adding swap fix it?
It makes a 1 or 2 GB board usable, which is why OpenClaw's Pi setup adds a 2 GB swap file. It does not make it fast, and swap on an SD card wears the card. Put swap on an SSD if you rely on it.

Sources