Garbage collection for scripts

Jython objects are java objects and are managed by java’s garbage collector.

There are two major sources of memory leaks, triggered by project updates:

  1. Persistent background threads that monitor sockets or serial ports or otherwise stay running for special reasons. They will keep running old code. You must use some mechanism (tag or client tag) to signal such threads that they’ve been replaced and need to shut themselves down.

  2. Jython implementations of java Listeners of various types. These will retain their old code until deliberated replaced. Or the event source ceases to exist–the listeners are cleaned up at that point.

I used to recommend the dictionary from system.util.getGlobals() as a safe place to track other objects through restarts. I now recommend my free Life Cycle module as a replacement.