Python script initialization

Hi Sanderd17,
thank you for your reply. One question: you say:

This method calls into the Java part of Ignition, and allows you to store more persistent data (only gets cleared on a gateway restart IIRC)

I thought that system.utils.getGlobals() was a dictionary of all the variables defined in the script scope (i.e. not in a function scope). So: how can I populate the dictionary that is returned by getGlobals? Is there anything like setGlobals?

However, the problem here seems that the object keeps listening, so the old script remains active but inaccessible.

Yes, you are right. To give GC a chance to collect unreferenced objects, I programmed a Python function where I remove listeners, close ports and set variables to None. If only I could call that function, I would be happy: after calling that function a heap dump with jmap shows that memory is clean, as far as my objects are concerned. The problem is: I have no chance to call that function and calling it from time to time is not so good, in my opinion.
Since the device data are needed only on one page or two, I could allocate/deallocate those objects depending on the page where the operator is. But if by chance the operator is just on those pages that need the device when I issue a save&publish, then ... BOOM!!