The problem was caused by a bug from Raspberry Pi OS. I know this because when I installed the python application in a new RPI5 with OS version 2025-10-01 the RAM consumption did not increase at all.