openHAB 3 runs out of memory / java heap space errors, CPU 100%+ after a few hours

Repeatable “Out of memory” found regarding large image items. I’ll document it here for others who might find it helpful.

OpenHab 3.1.0 Running on Pi4 4gb.
Bindings:

  • Amazon Echo
  • Astro
  • Epson Projector
  • Exec (used extensivly)
  • Harmony Hub
  • Ical
  • iRobot
  • Network
  • Onkyo
  • OpenGarage
  • OpenHab Zigbee
  • Open Weather
  • Roku (enabled but not in use yet)
  • System Info
  • Z-Wave
  • ZoneMinder

Extensive Use of HabPanel

I have 9 Lenovo M8 and M10 Tablets running habpanel Viewer to display screens, controls, cameras, etc. I have lots of large images and video streams that run over my wifi network. Some of these image items get stored as OpenHab image items.

Repeatable trigger events: Updating image items too quickly WILL trigger Java Heap OOM events. Example 9 tablets and 12 Zoneminder cameras pushing high res image items to OpenHab every few seconds will normally function correctly. HOWEVER if my wifi is congested or performing poorly, The tablets and camera images will try to update more frequently than they can finish. This leads to a pileup of image items spawning and murdering the java heap.

A hacky work around I have is an exec item that grabs the current max java heap percentage, If it exceeds 50% the rule that updates the images is skipped for an iteration. If the heap exceeds 90% a restart/reload command is sent to my tablets. This clears out any image queues that have pilled up.