[REQUEST] Persistence of an object instance after Scripting Save

In order to pick up new/changed jython code in importable script modules, Ignition must start a new interpreter with scopes for each project and for the global scripting project. The first call into a script module after interpreter startup imports it, creating all top-level named objects in the script module (functions, classes, and module-scope variables). All jython objects referenced solely by the old interpreters are garbage collected with the interpreter. Any old jython objects (code or data) referenced by Ignition’s own java objects will persist, with any code objects holding onto and using the old interpreter, though most such cases clean up relatively quickly. The dangerous case is any thread started with system.util.invokeAsynchronous() – those won’t get cleaned up (still running old code) until its function completes or you deliberately kill it.

The system.util.getGlobals() dictionary is a location where you can deliberately persist objects across interpreter restarts. It is generally safe to put native jython or java objects in this dictionary, though some of those can also be changed due to module load/unload or edits in jython’s own standard library. It is unsafe to place your own jython classes or class instances or functions in this dictionary, as they will keep the code they were created with. If you must, you are responsible for replacing such objects with new ones during your script modules’ import phase. If you fail to do so, you will leak the memory held by the old interpreter in its entirety.