Encountering "JavaScript heap out of memory" and Other Issues with Node-RED

Hello Node-RED Community,

I've been encountering a "JavaScript heap out of memory" error in my Node-RED environment. This suggests that my flows might be processing too much data at once or possibly have a memory leak. I've tried increasing the memory available to Node-RED with the --max-old-space-size flag, but then I run into issues finding the correct module path.

In my .node-red directory, there are several backup files which I've been managing while trying to preserve my current configuration and possibly restore from a backup if needed.

Upon inspecting my flows.json file, I notice there's a mix of disabled and enabled flows. I'm unsure if this is causing any issues, or if there are flows that I should be activating instead.

Additionally, my Node-RED dashboard has a complex setup with custom themes which might be contributing to the configuration challenges.

I need help identifying the root cause of the memory error and resolving the module path issues. Furthermore, I would appreciate any guidance on managing my flows and ensuring the dashboard is configured correctly.

Any advice on these matters would be greatly appreciated.

Please note that this DOES NOT do what most people think. It does not enable your Node.js app (Node-RED in this case) to use more memory directly. Rather, it steers how much memory is available to the "old" section of the heap. Whether this helps in a specific out of heap issue is complex.

Here are a couple of articles that may help:

Mark-Compact is the last attempt by the Garbage Collector to create a large enough contiguous memory space to hold a JavaScript object that has been amended and made larger. The articles above explain what all the numbers mean.

While you could increate max old space to close to the physical memory in your device, this may well cause other issues - notably SWAP activity which will generally kill the performance of the device and any services it is running.

The V8 engine that Node.js uses is actually very good a memory allocation these days, so assuming that you are using a current version of Node.js, it is rare that setting max old space will actually help.

The first thing I would recommend is removing the max old space setting completely and seeing if Node.js can work things out itself.

Looking at the first screen you are using charts.
Try reducing the datapoints send to the charts and the number of charts used.