Closed ancientloregames closed 7 years ago
You might consider looking at the features in PR #201.
Depending on the results of the PR, these features will be implemented in a separate github project or added to J2V8 in an upcoming release.
@Mizumi thanks a lot for such a quick answer! You've committed great addition to the project. After some testing, few questions have appeared, though.
V8JavaCache.removeGarbageCollectedJavaObjects();
, those instances still exists in heap. Whats correct way to fully delete object?No problem; glad you like it!
It's possible there's a subtle bug I'm missing, but more than likely there is another reference being held to those objects which prevents it from being collected. You may consider invoked System.gc()
immediately after V8JavaCache.removeGarbageCollectedJavaObjects()
to see if that helps; I'm currently modifying this code so it's non-static and more robustly performs garbage collection.
I have a suspicion it's referring to the V8 GC due to a distinct lack of Java GC invocations in that source code, but @irbull would know best.
I've been reviewing the source code, and there is actually no reason for that invocation. I believe I may have included it with the purpose of preventing objects from being prematurely garbage collected, but there appear to be no issues in testing related to that. I will be removing it from my test source and updating this PR or the project that comes out of it.
Cool news! Hope, you'll share your improvements with the community. The essential new feature will be auto binding of the class properties to js and additional annotation of properties and methods to bind. I've invented this features in our project, but, you're definitely more competent of how to do this the right way. Thanks for your answers and time!
Our teams is currently under consideration of witch Javascript Engine Bridge to use. We are choosing between J2V8 and LiquidCore. Supposedly, I have to create several instances of some java class in javascript, how can one achieve this in J2V8 using standard instantiation annotation (new ClassName())? In liquidcore you can bind some class, that extends JSFuction, with super constructor:
JSFunction(JSContext ctx, final String methodName, final Class<?extends JSObject> instanceClass)
and register property with desired class name like this:jsBaseContext.getJsContext().property("WebSocket", this);
and then on calling:var x = new WebSocket();
java method methodName will fire, where we'll get new instanceClass as JSValue object as parameter, already binded and ready to use in javascript.