Openhab memory leak - how to find

Regular java heap memory.

Version: 4.3.5 (Build) (but also on lower version)

pi@HOME:~ $ pidstat -r -p 21358 5
Linux 6.1.77-v8+ (HOME)         08/05/25        _aarch64_       (4 CPU)

10:15:03      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
10:15:08      106     21358      0.80      0.20 4643376  338120  36.34  java
10:15:13      106     21358     92.60      4.60 4643376  338172  36.35  java
10:15:18      106     21358     53.40      4.60 4643376  338212  36.35  java
10:15:23      106     21358     70.00      5.60 4643376  338324  36.36  java
10:15:28      106     21358     79.60      5.00 4643376  338500  36.38  java
10:15:33      106     21358      7.39      1.40 4643376  338548  36.39  java
10:15:38      106     21358     23.80      0.20 4643376  338560  36.39  java
10:15:43      106     21358      1.80      1.20 4643376  338560  36.39  java
10:15:48      106     21358      3.60      0.40 4643376  338564  36.39  java
10:15:53      106     21358      0.00      0.00 4643376  338564  36.39  java
10:15:58      106     21358     10.60      0.60 4643376  338588  36.39  java
10:16:03      106     21358    330.00     55.00 4643376  340088  36.55  java
10:16:08      106     21358      4.80      1.60 4643376  340092  36.55  java
10:16:13      106     21358      0.00      0.00 4643376  340092  36.55  java
10:16:18      106     21358      8.80      0.60 4643376  340120  36.56  java
10:16:23      106     21358      7.20      2.40 4643376  340280  36.57  java
10:16:28      106     21358      1.00      0.00 4643376  340284  36.57  java
10:16:33      106     21358      0.60      0.00 4643376  340284  36.57  java
10:16:38      106     21358      3.20      0.60 4643376  340340  36.58  java
10:16:43      106     21358      2.00      0.80 4643376  340340  36.58  java
10:16:48      106     21358     19.40      1.40 4643376  340416  36.59  java
10:16:53      106     21358      2.80      0.20 4643376  340416  36.59  java
10:16:58      106     21358     27.60      0.60 4643376  340444  36.59  java
10:17:03      106     21358      0.40      0.20 4643376  340444  36.59  java
10:17:08      106     21358     18.00      6.80 4643376  340624  36.61  java
10:17:13      106     21358      9.60      0.80 4643376  340624  36.61  java
10:17:18      106     21358      0.00      0.00 4643376  340624  36.61  java
10:17:23      106     21358      0.40      0.00 4643376  340624  36.61  java
10:17:28      106     21358      0.20      0.00 4643376  340628  36.61  java
10:17:33      106     21358     13.80      3.20 4643376  340760  36.62  java
10:17:38      106     21358      0.40      0.00 4643376  340768  36.63  java
10:17:43      106     21358      2.80      0.80 4643376  340768  36.63  java
10:17:48      106     21358      1.00      0.00 4643376  340768  36.63  java
10:17:53      106     21358      9.80      1.40 4643376  340768  36.63  java
10:17:58      106     21358      3.80      0.20 4643376  340820  36.63  java
10:18:03      106     21358     33.20     10.20 4643376  341040  36.65  java
10:18:08      106     21358     16.20      4.60 4643376  341172  36.67  java
10:18:13      106     21358      0.00      0.00 4643376  341172  36.67  java
10:18:18      106     21358      8.80      3.40 4643376  341172  36.67  java
10:18:23      106     21358      0.60      0.00 4643376  341224  36.67  java
10:18:28      106     21358     17.20      1.80 4643376  341384  36.69  java
10:18:33      106     21358      0.00      0.00 4643376  341384  36.69  java
10:18:38      106     21358      0.60      0.00 4643376  341384  36.69  java
10:18:43      106     21358      2.60      1.40 4643376  341500  36.70  java
10:18:48      106     21358      2.80      0.00 4643376  341500  36.70  java
10:18:53      106     21358      1.00      1.00 4643376  341568  36.71  java
10:18:58      106     21358     12.60      1.80 4643376  341568  36.71  java

10:18:58      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
10:19:03      106     21358     15.20      2.60 4643376  341600  36.72  java
10:19:08      106     21358     11.00      2.20 4643376  341652  36.72  java
10:19:13      106     21358      0.20      0.00 4643376  341652  36.72  java
10:19:18      106     21358      0.00      0.00 4643376  341652  36.72  java
10:19:23      106     21358      0.40      0.00 4643376  341652  36.72  java
10:19:28      106     21358      0.20      0.00 4643376  341652  36.72  java
10:19:33      106     21358      0.80      0.20 4643376  341652  36.72  java
10:19:38      106     21358     18.00      3.60 4643376  341704  36.73  java
10:19:43      106     21358      3.60      0.00 4643376  341704  36.73  java
10:19:48      106     21358     18.00      8.80 4643376  341736  36.73  java
10:19:53      106     21358      0.20      0.00 4643376  341736  36.73  java
10:19:58      106     21358      0.60      0.00 4643376  341736  36.73  java
10:20:03      106     21358     14.00      3.20 4643376  341804  36.74  java
10:20:08      106     21358      4.60      1.20 4643376  341944  36.75  java
10:20:13      106     21358      0.00      0.00 4643376  341944  36.75  java
10:20:18      106     21358     11.80      3.00 4643376  342028  36.76  java
10:20:23      106     21358     21.20      5.20 4643376  342028  36.76  java
10:20:28      106     21358     44.60     10.00 4643376  342476  36.81  java
10:20:33      106     21358      7.60      3.20 4643376  342528  36.81  java
10:20:38      106     21358     13.80      2.20 4643376  342572  36.82  java
10:20:43      106     21358     14.40      5.40 4643376  342572  36.82  java
10:20:48      106     21358      6.60      1.20 4643376  342572  36.82  java
10:20:53      106     21358      2.60      0.20 4643376  342572  36.82  java
10:20:58      106     21358      5.40      0.40 4643376  342608  36.82  java
10:21:03      106     21358     14.60      0.40 4643376  342892  36.85  java
10:21:08      106     21358      4.80      0.00 4643376  342904  36.86  java
10:21:13      106     21358      0.20      0.00 4643376  342904  36.86  java
10:21:18      106     21358      0.60      0.00 4643376  342904  36.86  java
10:21:23      106     21358     32.20      0.60 4643376  342924  36.86  java
10:21:28      106     21358      0.00      0.20 4643376  342924  36.86  java
10:21:33      106     21358      3.40      1.40 4643376  342924  36.86  java
10:21:38      106     21358      9.80      2.60 4643376  342980  36.86  java
10:21:43      106     21358      0.20      0.00 4643376  342980  36.86  java
10:21:48      106     21358     23.20      2.00 4643376  343160  36.88  java
10:21:53      106     21358      9.80      2.00 4643376  343264  36.89  java
10:21:58      106     21358      5.80      1.20 4643376  343268  36.89  java
10:22:03      106     21358      1.80      0.60 4643376  343268  36.89  java
10:22:08      106     21358     29.60      4.20 4643376  343504  36.92  java
10:22:13      106     21358      0.20      0.00 4643376  343504  36.92  java
10:22:18      106     21358      0.40      0.20 4643376  343504  36.92  java
10:22:23      106     21358      0.60      0.00 4643376  343504  36.92  java
10:22:28      106     21358      4.00      0.60 4643376  343504  36.92  java
10:22:33      106     21358     12.20      7.60 4643376  343504  36.92  java
10:22:38      106     21358      2.80      1.80 4643376  343592  36.93  java
10:22:43      106     21358      0.00      0.20 4643376  343592  36.93  java
10:22:48      106     21358      2.20      0.40 4643376  343684  36.94  java
10:22:53      106     21358      1.40      0.20 4643376  343704  36.94  java

10:22:53      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
10:22:58      106     21358      0.20      0.20 4643376  343704  36.94  java
10:23:03      106     21358      8.20      1.80 4643376  343704  36.94  java
10:23:08      106     21358      1.20      0.80 4643376  343704  36.94  java
10:23:13      106     21358      0.00      0.00 4643376  343704  36.94  java
^C
Average:      106     21358     13.17      2.10 4643376  341507  36.70  java

10:30:10      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
10:30:15      106     21358      7.40      0.00 4643376  351028  37.73  java
^C
Average:      106     21358      7.40      0.00 4643376  351028  37.73  java


11:08:54      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
11:08:59      106     21358      0.40      0.20 4649496  417452  44.87  java
11:09:04      106     21358      2.60      1.20 4649496  417536  44.88  java
11:09:09      106     21358      0.00      0.00 4649496  417536  44.88  java
11:09:14      106     21358      0.00      0.00 4649496  417536  44.88  java
^C
Average:      106     21358      0.75      0.35 4649496  417515  44.87  java


defaults: EXTRA_JAVA_OPTS=“-Xms250m -Xmx380m”

openjdk 17.0.14 2025-01-21 LTS
OpenJDK Runtime Environment Zulu17.56+15-CA (build 17.0.14+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.56+15-CA (build 17.0.14+7-LTS, mixed mode, sharing)
pi@HOME:~ $ cat /etc/os-release
PRETTY_NAME=“Debian GNU/Linux 12 (bookworm)”
NAME=“Debian GNU/Linux”
VERSION_ID=“12”
VERSION=“12 (bookworm)”
running on raspberry pi 3b

openhab> bundle:list | grep Add-ons
278 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting
279 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Automation :: PID Controller
280 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Automation :: PWM
281 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Exec Binding
282 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: HTTP Binding
283 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Modbus Binding
284 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: E3DC Modbus Binding
285 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: HeliosEasyControls Binding
286 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Modbus SBC Binding
287 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: StiebelEltron Bundle
288 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Studer Binding
289 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Modbus Sungrow Binding
290 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: SunSpec Bundle
291 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT Broker Binding
292 x Active x  81 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT EspMilightHub
293 x Active x  81 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT FPP
294 x Active x  81 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT Things and Channels
295 x Active x  82 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT HomeAssistant Convention
296 x Active x  82 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT Homie Convention
297 x Active x  82 x 4.3.5                 x openHAB Add-ons :: Bundles :: MQTT Ruuvi Gateway
315 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: IO :: Homekit
316 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: IO :: openHAB Cloud Connector
317 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Persistence Service :: MapDB
318 x Active x  80 x 4.3.5                 x openHAB Add-ons :: Bundles :: Persistence Service :: RRD4j
319 x Active x  75 x 4.3.5                 x openHAB Add-ons :: Bundles :: Transformation Service :: Exec
320 x Active x  75 x 4.3.5                 x openHAB Add-ons :: Bundles :: Transformation Service :: Jinja
321 x Active x  75 x 4.3.5                 x openHAB Add-ons :: Bundles :: Transformation Service :: JSonPath
322 x Active x  75 x 4.3.5                 x openHAB Add-ons :: Bundles :: Transformation Service :: Map
323 x Active x  75 x 4.3.5                 x openHAB Add-ons :: Bundles :: Transformation Service :: RegEx
327 x Active x  80 x 4.3.2                 x SmartHome/J Add-ons :: Bundles :: Tuya Binding
328 x Active x  80 x 4.3.2                 x SmartHome/J Add-ons :: Bundles :: Common Components

logs are pretty clear on a default debug level. For now the modbus client is disabled as a thing

what are the next steps to check what is causing the increasing mem usage

Unless you know how to use a Java profiler, the next steps are to systematically disable/remove bindings until the memory leak appears to go away, Then you know which add-on is the likely culprit.

See also:

1 Like

1GB of RAM for a 64bit PiOS is in general too little memory. Maybe try 32bit PiOS

Yes why do you limit the memory so much? It requires at least a couple of Gigabytes to work properly.

Mem usage increase per se does not mean a leak. it doesn’t have the look of a classic mem leak. 4.7GB is typical usage for 64bit ARM.
What’s your symptoms other than that figure?

Thank you for your answers, there is a java heap memory - out of memory happening from time to time even in a stable load. It was not happening earlier so it’s not connected to max ram / free ram but i now 1GB is not perfect solution, but it was running ok.
i already removed some modbus registery reads which ofter received a timeout. it seems stable now but today is

11:43:25 106 3490 0.00 0.00 4688660 487700 52.42 java
^C
Average: 106 3490 1.65 0.17 4694288 491758 52.85 java

i will take a closer look at this and let you know if it happens again.

The OH process grows a little in operations and with every new version usually needs a little more mem.
But that doesn’t mean leakage. Now still at some point in time you’re simply hitting a process limit.
If you had told us about and had shown the OOM message we could have told you.

If I was to guess, your problem is that you have artificially set a too tight max heap size PLUS you are using a 64 bit image which needs more mem than a 32 bit one.

Why aren’t you using openHABian?