Scanned images stay in memory and never get freed
After packaging a python script using libinsane
using cx_Freeze
into an executable and running it as a service, I noticed that the RAM usage increases with each scan and never goes down even after the scan is done and the images are retrieved, sometimes reaching upwards of 1GB of RAM usage.
I also noticed the following log present in logs after each scan was done:
warning: ../subprojects/libinsane/src/workarounds/cache.c:L597(cache_cleanup): cache->cleanup(): Device '{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0002' wasn't closed (refcount=1). Closing now
So i checked the workaround: os.environ["LIBINSANE_WORKAROUND_CACHE"]
and setting it to "1"
and "0"
did not change anything.
The scanner is HP LaserJet M1212nf MFP. Platform is Windows 10 (x32 and x64).
UPDATE: I found the issue and it was hinted at by the docs at LIBINSANE_WORKAROUND_CACHE section saying
Also keep track of the items. Return the same items as long as they haven't been closed. This reduce risk of programming error (even more when using the GObject layer). (which was exactly what I needed to do)