Love this notebook. Just a couple ideas/questions regarding memory management: In my experience it's basically awful, although I've previously tried using Observable's `invalidation` builtin to explicitly manage resources, so that before any cell is executed, it first cleans up previously allocated resources. It's awful though.
Otherwise, it seems like maybe embind maybe makes use of FinalizationRegistry so that perhaps you just leak resources and _hope_ they get cleaned up? https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management
Perhaps it's similar for rust/wasm-bindgen and the `--weak-refs` flag? https://rustwasm.github.io/wasm-bindgen/reference/weak-references.html
Just curious if you have any experience with any of the above since it really seems like memory management kind of holds back building proper ergonomic JS interfaces on top of native libraries.
Memory management is definitely awful. I think in general wasm-bindgen pushes you towards manual memory management. From Rust, you do have the option of either taking objects by value or by reference. When you take by value, wasm-bindgen will neuter the existing struct and move its pointer to 0. When you take by reference, you need to remember to call `.free()` on the original struct.
I read the wasm-bindgen docs on `--weak-refs` but they do say that it might take a while for resources to get cleaned up. So for now I'm trying to nudge towards manual management, and documenting which functions pass by value/by reference (e.g. the `into_*` functions pass by value).
I really don't have good ideas on how to make memory management easier here. Maybe eventually there will be a pure-js library on top of the wasm code presenting an easier interface