New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added SWIG #define to call v8 garbage collector #343
Conversation
The destructors in our nodeJS-wrapped C++ classes weren’t being invoked— even on termination. v8 doesn’t guarantee gc— even on scope closing or program termination. We need to call gc manually. Adding a #define lets us call 1 SWIG function that will be maintained— instead of having many #ifdefs.
|
Is this meant to be called automatically from the generated code, or is it something that users are expected to use? If the former, then you need to actually generate calls to it in the appropriate places. If the latter, it needs adding to the documentation so that users can know how to use it. |
|
We're currently using it as the latter. We're wrapping v8 GC in a global-scope function in our .i file. Then the JS can call that function whenever it wants to clear dead memory. So yeah-- I should also contribute to the SWIG documentation on this! Though I'm not sure where to start documenting this. Do you want some comment about gc in 26.2.3 Known Issues? Do you want a new section "26.5.6 Handling Garbage Collection in SWIG v8"? This PR could be the first step towards the former-- adding some type of gc to swig JS. Possible future addition ideas I'm bouncing around: |
|
A new section sounds reasonable to me. |
|
I have a question! It involves adding a new SWIG feature: allowing per-language auto-included code into .i files. If a language has a file called "interface_lang_defaults.i" in its library folder, the code will be processed as if a user added it at the end of his/her .i file. For example: I put a v8 gc function in interface_lang_defaults.i and then moved it to Lib/javascript/v8/. Now everybody wrapping C++ classes with nodeJS can call v8 garbage collection. Note that this should also let you destroy C++ primitives such as int16 or uint16 that you send to JS using %array_class. Is "per-language auto-included code" a desired feature?
Thank you very much!!!! |
|
Can you share what is going into the auto-included code? Without more details, the "per-language auto-included code" feature sounds like an extra complication to an already complex tool! Can you look at using the current directives - typemaps, %feature, %insert, %include %pythoncode (equivalent needed in JS) to add additional code? It sounds like this garbage collection should be generated by default to me though or maybe turned on via a %feature. Is gc implemented for node and jsc? If so, inspiration for turning it on should be taken from these implementations. @oliver---- is this missing garbage collection just a bug / oversight in the current implementation? @Richie765 any comments given your v8 usage? |
|
The code I'd auto-include would be the following: %{ Having sat on this a bit, this has developed a bit. I included the above cleanup code in Any language that has a file interface_lang_defaults.i would get the code If this makes more sense as a %feature, then I'm all for that!
I haven't yet been able to get this to work as a %feature.... But I tried I'm still working on getting my head around GC and JavaScriptCore, and Thank you very much!!!! On Tue, Feb 24, 2015 at 6:38 PM, William S Fulton notifications@github.com
|
|
Closing with the suggestion that anyone who wants to call the |
The destructors in our nodeJS-wrapped C++ classes weren’t being invoked— even on termination.
v8 doesn’t guarantee gc— even on scope closing or program termination.
We need to call gc manually.
Adding a #define lets us call 1 SWIG function that will be maintained— instead of having many #ifdefs.