-
I've played around a bit with Javet and noticed some memory notifications. Here is a test to reproduce: public class JavetTest {
@Test
void testVar() {
for (String script : new String[] {
"var b = a;",
"var b = a; b = undefined;"}) {
System.out.println("Execute script: " + script);
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
v8Runtime.setConverter(new JavetProxyConverter());
v8Runtime.getGlobalObject().set("a", new A());
v8Runtime.getExecutor(script).executeVoid();
v8Runtime.getGlobalObject().delete("a");
v8Runtime.lowMemoryNotification();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class A {}
} And the result is:
So do I have to set all with a proxyobject assigned variables in Javascript to undefined before the script ends, or is there a way around this? |
Beta Was this translation helpful? Give feedback.
Answered by
caoccao
Feb 3, 2022
Replies: 1 comment 1 reply
-
The root cause of the potential memory leak is: global objects are not subject to GC. The solution is as follows.
Why potential? Javet keeps track of every memory leak point and releases all of them when V8 runtime is being closed. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Stechmuck
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The root cause of the potential memory leak is: global objects are not subject to GC.
The solution is as follows.
let
,const
instead ofvar
.Why potential? Javet keeps track of every memory leak point and releases all of them when V8 runtime is being closed.