# JavaScript heap out of memory after message processing ends

**URL:** https://discourse.nodered.org/t/javascript-heap-out-of-memory-after-message-processing-ends/97775
**Category:** General
**Tags:** docker, debug
**Created:** [24 June 2025 12:38 UTC](https://discourse.nodered.org/t/javascript-heap-out-of-memory-after-message-processing-ends/97775 "2025-06-24T12:38:37Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [24 June 2025 12:58 UTC](https://discourse.nodered.org/t/javascript-heap-out-of-memory-after-message-processing-ends/97775/2 "2025-06-24T12:58:44Z")

</div>

Hi, welcome to the forum.

> [@KronwarsCZ](#):
>
> While testing, I can see a sudden jump in CPU usage to 100% and memory jump from normal 950MB to 1.2 GB, followed by a crash.

> [@KronwarsCZ](#):
>
> As far as I can tell, the message is processed and no loop is happening

I know, but really does smell like an uncontrolled loop (or recursion)

> [@KronwarsCZ](#):
>
> Do you have any ideas as to why this might be happening

There are many threads on the forum for this topic: [Search results for '"JavaScript heap out of memory" order:latest' - Node-RED Forum](https://discourse.nodered.org/search?q=%22JavaScript%20heap%20out%20of%20memory%22%20order%3Alatest)

This one was a little different.

> [@Flowfuse Device Agent crashes. FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory](https://discourse.nodered.org/t/flowfuse-device-agent-crashes-fatal-error-reached-heap-limit-allocation-failed-javascript-heap-out-of-memory/96822/2):
>
> The error get thrown in a variety of situations, here are a few:
> 
> - When attempting to process large amounts of data or execute complex algorithms that require a lot of memory.
> - When running a Node.js server with a large number of connections or concurrent requests.
> - When running a Node.js application in a container or virtual machine with limited memory resources.

which was resolved like this:

> [@Flowfuse Device Agent crashes. FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory](https://discourse.nodered.org/t/flowfuse-device-agent-crashes-fatal-error-reached-heap-limit-allocation-failed-javascript-heap-out-of-memory/96822/4):
>
> we do add `--max_old_space_size=512`. What that means is when this heap fills up, Node.js needs to perform a garbage collection (GC) cycle. Coupled with your comment about "now not able to modify flows" (_my mind reads "you have recently modified flows"_) from that, I dont think it is a stretch to conclude _something has changed_ and the GC is now unable able to keep up with memory allocations.
> 
> Are you able to try something out? If possible, edit the file `lib/launcher.js` in your device agent installation and change the line to something like '--max\_old\_space\_size=1024' (or remove it altogether)

Where you set `max_old_space_size` will depend on how you are running node-red (do a search)

but the 100% CPU spike really really smells like a hard, blocking loop - so perhaps a buggy contrib? or some recursive (self calling) function node code? or an _invisible_ loop caused by link nodes or MQTT?

---

_[View the full topic](https://discourse.nodered.org/t/javascript-heap-out-of-memory-after-message-processing-ends/97775)._
