Given that a VirtualMachine could potentially take up a lot of memory, what would be the smartest way to make a JS class to manage it? The pyEval function is sufficient for simple things, but it might be desirable to persist the context over, e.g. for a REPL.
I see two or three ways to do this:
- Hold created
VirtualMachines in a global HashMap by randomly generated IDs, and have a .destroy() method on the JS class that has to be called or risk a memory leak.
- Only allow one
VirtualMachine per JS context, held in a global variable, initialized at load.
- Implement a way for the entire Python context to be serialized (probably not feasible at the moment, nor necessarily worth the time).
I considered some stuff with maybe JS WeakSets or WeakMaps (that take an object as a key but don't prevent it or its value from being garbage-collected), but I don't think that would be able to do anything.
Given that a
VirtualMachinecould potentially take up a lot of memory, what would be the smartest way to make a JS class to manage it? ThepyEvalfunction is sufficient for simple things, but it might be desirable to persist the context over, e.g. for a REPL.I see two or three ways to do this:
VirtualMachinesin a global HashMap by randomly generated IDs, and have a.destroy()method on the JS class that has to be called or risk a memory leak.VirtualMachineper JS context, held in a global variable, initialized at load.I considered some stuff with maybe JS
WeakSets orWeakMaps (that take an object as a key but don't prevent it or its value from being garbage-collected), but I don't think that would be able to do anything.