I've discovered a slow memory leak in my plugin, having isolated things to determine that it is definitely the cause. Running
htop shows me no less than 39 instances of python running OctoPrint of which 21 of these are from my plugin.
It looks like
htop probably isn't the tool for troubleshooting this because the memory-related values are lumping all 39 process IDs together for those amounts. Likewise,
mem just gives totals. I've attempted to use the technique below within each of my classes...
from resource import getrusage, RUSAGE_SELF ... def DisplayMemoryUsed(self): try: op.obj._logger.info('ClassName() usage: ' + str(getrusage(RUSAGE_SELF).ru_maxrss)) except Exception as e: op.obj._logger.info('Failed to track memory...' + str(e))
...unfortunately it's not giving me the individual object's memory, it's just showing some growing aggregate of the plugin itself. It looks like the python v2.7.13 that I'm using doesn't support the RUSAGE_THREAD value for
I've tried commenting out any calls to
Clock.schedule_interval() which might have run code on a recurring basis but this hasn't really slowed the slow drain of RAM.
I guess next I'll try to force garbage collection at some python level but I'm open to suggestions.