On Mon, Mar 23, 2015 at 12:44 PM, Brion Vibber <[email protected]> wrote:
> 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! > 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). > Agreed. That's what we do at IMVU. It's unfortunate. > 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. :( > Yup, WeakMap is constructed such that it doesn't actually give any insight into the behavior of the JS GC. :( > 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. :) > Interesting idea! > 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? > Nope, we do it the hard way. :/ It sucks, but if you have enough visualizations and leak detection in unit tests, it sort of works OK in practice. > > -- 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. > -- Chad Austin Technical Director, IMVU http://engineering.imvu.com <http://www.imvu.com/members/Chad/> http://chadaustin.me -- 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.
