Managing xray's High RAM Usage Over Time: Tips for Memory Optimization

I have a MikroTik RouterBOARD 750Gr3 with OpenWrt 22.03.5. I have installed the latest version of xray, 1.8.3. However, I am facing an issue with its RAM usage over time. The RAM usage increases gradually until the free memory becomes around 10MB, and then the xray service crashes. Is there anything I can do to address this problem? I have set up a cron job to restart the service every hour, but I'm looking for a more permanent solution to manage its memory usage effectively.

xray service file:

#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

#####  ONLY CHANGE THIS BLOCK  ######
PROG=/usr/bin/xray # 
CONF=/etc/xray/config.json   # where is the config file, it can be a relative path to $RES_DIR
#####  ONLY CHANGE THIS BLOCK  ######

start_service() {
  procd_open_instance
  procd_set_param command $PROG --config $CONF

  procd_set_param user root
  procd_set_param limits core="unlimited"
  procd_set_param limits nofile="1000000 1000000"
  procd_set_param stdout 1
  procd_set_param stderr 1
  procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
  procd_close_instance
  /usr/sbin/nft -f /etc/xray/nftables.conf
  /sbin/ip route add local default dev lo table 100
  /sbin/ip rule add fwmark 1 table 100
  echo "xray is started!"
}

stop_service() {
  service_stop $PROG
  /usr/sbin/nft flush table ip xray
  /sbin/ip route del local default dev lo table 100
  /sbin/ip rule del table 100
  echo "xray is stopped!"
}

reload_service() {
  /usr/sbin/nft -f /etc/xray/nftables.conf
  stop
  sleep 2s
  echo "xray is restarted!"
  start
}

xray config file

{
    "inbounds": [
      {
        "tag": "all-in",
        "port": 12345,
        "protocol": "dokodemo-door",
        "settings": {
          "network": "tcp,udp",
          "followRedirect": true
        },
        "sniffing": {
          "enabled": true,
          "destOverride": ["http", "tls"]
        },
        "streamSettings": {
          "sockopt": {
            "tproxy": "tproxy"
          }
        }
      }
    ],
    "outbounds": [
      {
        "tag": "direct",
        "protocol": "freedom",
        "settings": {
          "domainStrategy": "UseIPv4"
        },
        "streamSettings": {
          "sockopt": {
            "mark": 2
          }
        }
      },
      {
        "protocol": "vless",
        "settings": {
          "vnext": [
            {
              "address": "",
              "port": 443,
              "users": [
                {
                  "id": "",
                  "encryption": "none",
                  "flow": ""
                }
              ]
            }
          ]
        },
        "streamSettings": {
          "network": "h2",
          "security": "reality",
          "realitySettings": {
            "show": false,
            "fingerprint": "chrome",
            "serverName": "",
            "publicKey": "",
            "shortId": "",
            "spiderX": ""
          }
        },
        "tag": "proxy"
      },
      {
        "tag": "block",
        "protocol": "blackhole",
        "settings": {
          "response": {
            "type": "http"
          }
        }
      },
      {
        "tag": "dns-out",
        "protocol": "dns",
        "settings": {
          "address": "8.8.8.8"
        },
        "proxySettings": {
          "tag": "proxy"
        },
        "streamSettings": {
          "sockopt": {
            "mark": 2
          }
        }
      }
    ],
    "routing": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "type": "field",
          "inboundTag": ["all-in"],
          "outboundTag": "proxy"
        }
      ]
    }
  }

Thanks for you help

Actually, xray is up to 1.8.16. There have been a few fixes regarding memory leaks, and connection leaks. Will try to crosscompile xray 1.8.16, to run on openwrt.

Saw, that in master branch, xray 1.8.16 is set up. Having not the best expirience using master, I backported packages golang and xray from master to 22.03.06 . Build from src successful.