You can configure openHAB to restart automatically on OOM errors… This is what I have in place. Nowadays I do not have any OOM errors but it is good the protection just in case there would be some regressions.
In addition I have configured raspberry pi watchdog module with max cpu and memory on case something else is taking the memory or somehow gets locked out.
The whole system is read-only so restart will restore things into "known good state ".
The java parameter for exiting on OOM errors is
-XX:+ExitOnOutOfMemoryError
You need to configure systemd to restart the service on failures, if it is not the default.
I have switched to AdoptOpenJDK due to issues experienced with zulu java Syslog Errors (100 GB) - #38 by ssalonen
Otherwise this setup has been stable for me for the last couple of years, since openHAB1
zulu java (