I'm in the process of switching my ogv.js media player project from manual
C/JS bindings to using embind on some C++ classes, in preparation for
sharing more of the player logic with an iOS native version. It's pretty
easy to use once I got the hang of it, and I can even override property
getters to return raw memory views into the heap to pull WebGL textures to
the JS side. Great!

However I've found it's a bit ugly to have to explicitly call delete() on
every object that's bridged over to JS, and it can make it harder to write
idiomatic JS code that has an emcripten'd component...

For now I'm making extensive use of value objects for passing data around
which means I only have to delete() a few logic objects explicitly, but I
have the basic problem that the emscripten runtime won't get
garbage-collected when the media player is removed from the DOM (eg closing
a dialog/overlay with a player widget in it).

I briefly looked at the ES6 WeakMap construct as a way of making a list of
GC-ready handles but it looks insufficient as there's no way to get the
values associated with garbage-collected key objects. :(


One thing I can do is wrap the entire Module setup and initialization in a
function, then let the whole module and any remaining JS-bridged objects
get GC'd out as a group when there's no longer any DOM elements holding
indirect references to them... this "frees" the entire heap similarly to
ending a process. :)

Unfortunately this means each activated media player widget will hold its
own 16MB asm.js heap even when that memory could have been shared between
many of them. This is usually ok, but has some bad edge cases if a lot of
players are spawned, then left paused/stopped (as might happen on a page
with a lot of audio clips).

Any other clever embind-friendly GC strategies anyone's come up with?

-- brion vibber (brion @ pobox.com / bvibber @ wikimedia.org)

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to