Skip to content

[WASM] How would a VirtualMachine class work for binding to JS? #262

Description

@coolreader18

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions