FATAL ERROR: MarkCompactCollector

Hi folks!

i just wanted to update the 'node-red-contrib-smartnora' package and ran into the following error:

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory

My Node-Red instance is running on an rather old Raspberry Pi Model B Plus Rev 1.2. Unfortunately i have no experience with Java Script.

Any ideas on this?


2022-05-16T02:35:06.683Z Installieren : node-red-dashboard 3.1.7

2022-05-16T02:35:03.999Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-dashboard@3.1.7
2022-05-16T02:37:06.716Z [out] + node-red-dashboard@3.1.7
2022-05-16T02:37:06.716Z [out] removed 1 package and updated 11 packages in 112.117s
2022-05-16T02:37:07.054Z rc=0

2022-05-16T02:37:25.360Z Installieren : node-red-contrib-smartnora 1.13.5

2022-05-16T02:37:22.491Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-contrib-smartnora@1.13.5
2022-05-16T02:48:34.472Z [err] 
2022-05-16T02:48:34.472Z [err] <--- Last few GCs --->
2022-05-16T02:48:34.472Z [err] 
2022-05-16T02:48:34.472Z [err] [793:0x4779580]   663681 ms: Mark-sweep (reduce) 126.5 (128.6) -> 126.0 (129.1) MB, 3034.2 / 0.2 ms  (average mu = 0.294, current mu = 0.113) allocation failure scavenge might not succeed
2022-05-16T02:48:34.472Z [err] [793:0x4779580]   668203 ms: Mark-sweep (reduce) 126.6 (128.6) -> 126.1 (129.1) MB, 3920.3 / 0.2 ms  (average mu = 0.213, current mu = 0.133) allocation failure scavenge might not succeed
2022-05-16T02:48:34.472Z [err] 
2022-05-16T02:48:34.472Z [err] 
2022-05-16T02:48:34.472Z [err] <--- JS stacktrace --->
2022-05-16T02:48:34.472Z [err] 
2022-05-16T02:48:34.487Z [err] FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
2022-05-16T02:48:35.032Z rc=null

thank you in advance!

Essentially not enough memory on the device.

You might be able to (slightly) increase the allocation (as described in the above link) but ultimately, you might be constrained by the device.

Hello Samuel!

I did a bit of research on this topic and have few suggestions for you that might help.

What does the issue mean and what is the cause?

It means JavaScript has a lot of processes to handle, and the default heap memory allocated by Node.js (a JavaScript environment on top of which node-red is running) needs more space to process the script/program that you are currently running.
One of the scenarios when this happens is when the application batch processes a large set of data, and the data processing algorithm is written in a way such that it needs to hold onto the objects in heap space until the processing is done.

What can be done about this issue?

  1. Never declare variables with keyword "Var" unless necessary (it has a gobal scope and occupies huge amount of memory), rather use "let", "const"
  2. Good Practice: Always initialize arrays as an empty array
  3. Good Practice: Always use functions to do any operation, in that way the variables that only require local scope will go to the garbage collector immediately after you exit from the function.
  4. As a result, the freed memory can be allocated to other variables.
  • Good Practice: Use unsafe function node in Node-RED to do your JavaScript code, it uses less memory and is much faster than the usual function node of Node-RED.
  1. There is nothing unsafe about them, just that they do not run inside a VM
  2. In Node.js, the maximum heap size is not set, a default memory limit will be imposed, and this default value varies based on the Node.js version and architecture of the system the program is running in. Therefore, It is recommended to always explicitly set the heap size instead of relying on default imposed by Node.js. One more point, this maximum size can also be increased.
  3. The maximum heap size can be set/increased in the following manner:
    node --max-old-space-size=4096 index.js #increase to 4GB

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.