nbind icon indicating copy to clipboard operation
nbind copied to clipboard

"Light garbage collection" on Emscripten target

Open jjrv opened this issue 9 years ago • 0 comments

Together with supporting smart pointers, a simple GC could be added also on Emscripten target, enabled by calling bindings.enableLightGC(). C++ objects "owned" by JavaScript (created with JavaScript new operator or received through smart pointers) will be added to a list and freed automatically on the next tick, using setTimeout(..., 0);.

Pointers can be kept around for longer by calling their .persist() method, and later disposed by calling .free() same as currently. The default automatic freeing allows receiving temporary objects without having to worry about their lifetime.

Optional V8-style "handle scopes" could also be introduced. Any pointers received would then live as long as their scope. Scopes are opened upon creation and can be closed, re-opened and destroyed afterwards. Pointers are attached to the scope last opened. This would allow creating a bunch of temporary objects and later using and automatically freeing them from a callback or promise.

Todo:

  • [x] Light GC
  • [ ] Handle scopes

jjrv avatar Sep 01 '16 14:09 jjrv