# How to limit memory usage

**URL:** https://discourse.nodered.org/t/how-to-limit-memory-usage/85792
**Category:** General
**Created:** [23 February 2024 04:01 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792 "2024-02-23T04:01:43Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)
#### Post date: [23 February 2024 04:01 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/1 "2024-02-23T04:01:43Z")

</div>

I'm using a change node to "set flow.chart" to the value "msg.payload" to save my chart data, how do I limit how much it stores? I only want 7 days worth of data at most, and not just keep adding forever.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 February 2024 08:19 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/2 "2024-02-23T08:19:16Z")

</div>

If you are talking about dashboard chart, then you can set it to display 7 days and it will only output 7 days of data. Otherwise you would need to slice the output array and keep the last x elements (total elements for 7 days of data).

---

<div class="post-metadata">

### Author: ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)
#### Post date: [23 February 2024 17:13 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/3 "2024-02-23T17:13:59Z")

</div>

yes dashboard chart. Doesn't it store the data long term? It is persistent so it stays after a power cycle, and I load the data on power up

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 February 2024 17:32 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/4 "2024-02-23T17:32:45Z")

</div>

Chart node stores and outputs only the data set in the x-axis last or points, set in the chart config

---

<div class="post-metadata">

### Author: ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)
#### Post date: [23 February 2024 17:56 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/5 "2024-02-23T17:56:44Z")

</div>

But I'm taking the output of the chart to store the data, and I believe it appends the stored data so that it can be loaded on power up and then the chart only displays the last 7 days of data. But I think there is more data stored and the chart only loads what it needs to meet the set period of days? Unless I'm wrong on this?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 February 2024 18:12 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/6 "2024-02-23T18:12:38Z")

</div>

I refer you to my previous answer. The chart node only outputs what is shown, and that is set by the x-axis inputs in the chart config. Unless you are appending it to other stored data, but you have not shown any info for us to know that.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [23 February 2024 18:23 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/7 "2024-02-23T18:23:42Z")

</div>

> [@rmystique](#):
>
> I'm using a change node to "set flow.chart" to the value "msg.payload" to save my chart data

So how much data is in your flow.chart variable?

I don't think you have shown us anything to justify your concern that the data keeps on growing.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 February 2024 18:33 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/8 "2024-02-23T18:33:48Z")

</div>

> [@rmystique](#):
>
> But I think there is more data stored and the chart only loads what it needs to meet the set period of days

The node only stores what you see on the display.

---

<div class="post-metadata">

### Author: ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)
#### Post date: [23 February 2024 20:14 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/9 "2024-02-23T20:14:02Z")

</div>

```auto
[
    {
        "id": "739201a44f8b4af3",
        "type": "inject",
        "z": "f672d0ac69fd5b97",
        "name": "load2",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "0.5",
        "topic": "",
        "payload": "chart2",
        "payloadType": "flow",
        "x": 870,
        "y": 720,
        "wires": [
            [
                "36cdb53617faf1c5"
            ]
        ]
    },
    {
        "id": "36cdb53617faf1c5",
        "type": "ui_chart",
        "z": "f672d0ac69fd5b97",
        "name": "",
        "group": "8ee0bb75fa4e2113",
        "order": 23,
        "width": 6,
        "height": 5,
        "label": "Solar Charging",
        "chartType": "line",
        "legend": "true",
        "xformat": "auto",
        "interpolate": "linear",
        "nodata": "Solar Amps",
        "dot": false,
        "ymin": "0",
        "ymax": "100",
        "removeOlder": "3",
        "removeOlderPoints": "",
        "removeOlderUnit": "86400",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#0f80d2",
            "#e70d2e",
            "#f57a0f",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1040,
        "y": 740,
        "wires": [
            [
                "f42e8a37025b02ad"
            ]
        ]
    },
    {
        "id": "f42e8a37025b02ad",
        "type": "change",
        "z": "f672d0ac69fd5b97",
        "name": "save2",
        "rules": [
            {
                "t": "set",
                "p": "chart3",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1190,
        "y": 760,
        "wires": [
            [
                "138a814a6320d30d"
            ]
        ]
    },
    {
        "id": "8ee0bb75fa4e2113",
        "type": "ui_group",
        "name": "Main",
        "tab": "9d03c9290d696c27",
        "order": 1,
        "disp": false,
        "width": 12,
        "collapse": false,
        "className": ""
    },
    {
        "id": "9d03c9290d696c27",
        "type": "ui_tab",
        "name": "Solar Power Stats",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 February 2024 22:04 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/10 "2024-02-23T22:04:50Z")

</div>

How do you add new data to the chart?

---

<div class="post-metadata">

### Author: ![rmystique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rmystique/32/84365_2.png) [@rmystique](https://discourse.nodered.org/u/rmystique)
#### Post date: [24 February 2024 04:30 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/11 "2024-02-24T04:30:13Z")

</div>

```auto
[
    {
        "id": "ae0553679c5b2543",
        "type": "link in",
        "z": "f672d0ac69fd5b97",
        "name": "link in 2",
        "links": [
            "438617e01b830bc8"
        ],
        "x": 165,
        "y": 660,
        "wires": [
            [
                "0ac13c022bbdfb4a",
                "9513c969a881eb86"
            ]
        ]
    },
    {
        "id": "0ac13c022bbdfb4a",
        "type": "function",
        "z": "f672d0ac69fd5b97",
        "name": "Charge Conv",
        "func": "msg.payload = (((msg.payload) * .0818 )+.0818); .081\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 660,
        "wires": [
            [
                "71c5b793186fdcc8"
            ]
        ]
    },
    {
        "id": "71c5b793186fdcc8",
        "type": "smooth",
        "z": "f672d0ac69fd5b97",
        "name": "",
        "property": "payload",
        "action": "mean",
        "count": "5",
        "round": "",
        "mult": "single",
        "reduce": false,
        "x": 480,
        "y": 660,
        "wires": [
            [
                "90404ad4f7da1e1c",
                "61f2cf5e9c4d772d"
            ]
        ]
    },
    {
        "id": "61f2cf5e9c4d772d",
        "type": "switch",
        "z": "f672d0ac69fd5b97",
        "name": "zero",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "0",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 310,
        "y": 820,
        "wires": [
            [
                "7f4787605eed55ed",
                "781ab50bf2f08b19",
                "ba42fb48b881e044"
            ],
            [
                "e453d16b5dce47ea"
            ]
        ]
    },
    {
        "id": "7f4787605eed55ed",
        "type": "change",
        "z": "f672d0ac69fd5b97",
        "name": "solar 2",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "solar2",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 490,
        "y": 820,
        "wires": [
            [
                "e213b42ead503fb3",
                "1a9c070f341a26ba"
            ]
        ]
    },
    {
        "id": "1a9c070f341a26ba",
        "type": "delay",
        "z": "f672d0ac69fd5b97",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "minute",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 870,
        "y": 760,
        "wires": [
            [
                "36cdb53617faf1c5"
            ]
        ]
    },
    {
        "id": "739201a44f8b4af3",
        "type": "inject",
        "z": "f672d0ac69fd5b97",
        "name": "load2",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "0.5",
        "topic": "",
        "payload": "chart2",
        "payloadType": "flow",
        "x": 870,
        "y": 720,
        "wires": [
            [
                "36cdb53617faf1c5"
            ]
        ]
    },
    {
        "id": "36cdb53617faf1c5",
        "type": "ui_chart",
        "z": "f672d0ac69fd5b97",
        "name": "",
        "group": "8ee0bb75fa4e2113",
        "order": 23,
        "width": 6,
        "height": 5,
        "label": "Solar Charging",
        "chartType": "line",
        "legend": "true",
        "xformat": "auto",
        "interpolate": "linear",
        "nodata": "Solar Amps",
        "dot": false,
        "ymin": "0",
        "ymax": "100",
        "removeOlder": "3",
        "removeOlderPoints": "",
        "removeOlderUnit": "86400",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#0f80d2",
            "#e70d2e",
            "#f57a0f",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1040,
        "y": 740,
        "wires": [
            [
                "f42e8a37025b02ad"
            ]
        ]
    },
    {
        "id": "f42e8a37025b02ad",
        "type": "change",
        "z": "f672d0ac69fd5b97",
        "name": "save2",
        "rules": [
            {
                "t": "set",
                "p": "chart3",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1190,
        "y": 760,
        "wires": [
            [
                "138a814a6320d30d"
            ]
        ]
    },
    {
        "id": "8ee0bb75fa4e2113",
        "type": "ui_group",
        "name": "Main",
        "tab": "9d03c9290d696c27",
        "order": 1,
        "disp": false,
        "width": 12,
        "collapse": false,
        "className": ""
    },
    {
        "id": "9d03c9290d696c27",
        "type": "ui_tab",
        "name": "Solar Power Stats",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [24 February 2024 08:21 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/12 "2024-02-24T08:21:53Z")

</div>

A description would have been sufficient.  
You appear to be adding a point every minute, with a chart span of 3 days, so there should never be more than 4320 points in the saved array.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [24 February 2024 08:51 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/13 "2024-02-24T08:51:06Z")

</div>

If you want to reduce the array size you can change the number of days to display or set the rate limit to a greater value, or move the smooth node to after the rate limit. Experiment, it really helps you learn.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 May 2024 08:52 UTC](https://discourse.nodered.org/t/how-to-limit-memory-usage/85792/14 "2024-05-24T08:52:00Z")

</div>

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