Are objects being created in the global scope everytime V8JavaObjectUtils#translateJavaArgumentToJavascript is called?
Opened this issue · 0 comments
I was looking at the source and it seems to me that the method to translate a java object to a javascript V8Value is creating a new global object on the global scope of the V8 runtime with a random UUID. Is my understanding correct about this?
If this is the case, I have to say this worries me a bit. I noticed there is a cache in place that checks if the object already exists to avoid creating it again, but in my use case that will be a very rare scenario. My application is a long running server that will be up for months without restarting, it will be receiving events quite frequently. Java methods with several arguments are triggered when these events happen, I'm then using the translateJavaArgumentToJavascript method to convert those arguments to javascript V8Values
and calling javascript functions using v8.executeJSFunction and passing those arguments to those javascript functions. That said, I only want those objects that I'm passing as arguments to exist inside that javascript function scope and not in the global scope, because if not, after a few months running my application, I will have a few hundred maybe thousand global objects on the global scope, and I'm concerned this is just not very memory effecient.
Is there a better way to handle this? Do java objects absolutely have to be injected into the global scope to convert them to V8 values?