eclipsesource / eclipsesource/J2V8
Releasing V8Objects in different method
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 387
- PR merge metrics
- No merged PRs in 30d
Description
```
private void executeObj(V8Object obj) {
V8Object root = new V8Object(runtime).add("name","A1");
V8Object B1 = new V8Object(runtime).add("name","B1");
V8Object B2 = new V8Object(runtime).add("name","B2");
B2.add("value",200);
V8Object C1 = new V8Object(runtime).add("name","C1");
C1.add("value",100);
V8Object C2 = new V8Object(runtime).add("name","C2");
C2.add("value",300);
V8Object C3 = new V8Object(runtime).add("name","C3");
C3.add("value",200);
V8Array A1Childrens = new V8Array(runtime).push(B1).push(B2);
A1.add("children",A1Childrens);
V8Array B1Childrens = new V8Array(runtime).push(C1).push(C2).push(C3);
B1.add("children",B1Childrens);
V8Object hierarchy = (V8Object) obj.executeJSFunction("doLayout", root);
hierarchy.close()
root.close();
A1Childrens.close();
B1.close();
B2.close();
B1Childrens.close();
C1.close();
C2.close();
C3.close();
}
```
In executeObjj() method, JS objects (method parameters) are created and released within the same method scope.
If I release the created objects in another function as follows, v8 runtime throws exception
```
private void release(V8Object A1) {
V8Array A1Array = A1.getArray("children");
V8Object B1 = A1Array.getObject(0);
V8Object B2 = A1Array.getObject(1);
V8Array B1Array = B1.getArray("children");
V8Object C1 = B1Array.getObject(0);
V8Object C2 = B1Array.getObject(1);
V8Object C3 = B1Array.getObject(2);
C1.close();
C2.close();
C3.close();
B1Array.close();
B1.close();
B2.close();
A1Array.close();
A1.close();
}
private void executeObj(V8Object obj) {
V8Object root = new V8Object(runtime).add("name","A1");
V8Object B1 = new V8Object(runtime).add("name","B1");
V8Object B2 = new V8Object(runtime).add("name","B2");
B2.add("value",200);
V8Object C1 = new V8Object(runtime).add("name","C1");
C1.add("value",100);
V8Object C2 = new V8Object(runtime).add("name","C2");
C2.add("value",300);
V8Object C3 = new V8Object(runtime).add("name","C3");
C3.add("value",200);
V8Array A1Childrens = new V8Array(runtime).push(B1).push(B2);
A1.add("children",A1Childrens);
V8Array B1Childrens = new V8Array(runtime).push(C1).push(C2).push(C3);
B1.add("children",B1Childrens);
V8Object hierarchy = (V8Object) obj.executeJSFunction("doLayout", root);
hierarchy.close()
release(A1);
}
```
v8Runtime.release() throwing illegalStateExeption() with 7 objects still exists in memory as follows
> java.lang.IllegalStateException: 7 Object(s) still exist in runtime
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
> at android.app.ActivityThread.-wrap11(Unknown Source:0)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
> at android.os.Handler.dispatchMessage(Handler.java:106)
> at android.os.Looper.loop(Looper.java:164)
> at android.app.ActivityThread.main(ActivityThread.java:6494)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
> Caused by: java.lang.IllegalStateException: 7 Object(s) still exist in runtime
> at com.eclipsesource.v8.V8.release(V8.java:388)
Whether getting children objects from same root object instance returns new child instances (like cloned instances) ? If so, how to release the V8Objects created in one function and releasing it in another function?
Contributor guide
Assessment
This issue has not been assessed yet.