Those are racy and prone to memory leaks. Always use .setdefault to reliably initialize a value in a dictionary when a check for the key's presence fails. When the value is an object that will be used all over the library, use the .setdefault technique to establish it as a top-level variable in the library.
Study this topic for the techniques needed to avoid crashing your gateway:
If you cannot use my globalVarMap(), you have to approximate it with an extra layer in system.util.getGlobals().