Give garbage collector a chance to GC something by existing the JavaScript loop few times
1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Mon Dec 08 18:04:10 2014 +0100
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Mon Dec 08 18:12:52 2014 +0100
1.3 @@ -42,12 +42,8 @@
1.4 */
1.5 package net.java.html.js.tests;
1.6
1.7 -import java.io.StringReader;
1.8 import java.lang.ref.Reference;
1.9 import java.lang.ref.WeakReference;
1.10 -import java.util.Arrays;
1.11 -import java.util.concurrent.Callable;
1.12 -import org.netbeans.html.boot.spi.Fn;
1.13 import org.netbeans.html.json.tck.KOTest;
1.14
1.15 /**
1.16 @@ -55,7 +51,13 @@
1.17 * @author Jaroslav Tulach
1.18 */
1.19 public class GCBodyTest {
1.20 + Reference<?> ref;
1.21 +
1.22 @KOTest public void callbackWithParameters() throws InterruptedException {
1.23 + if (ref != null) {
1.24 + assertGC(ref, "Can disappear!");
1.25 + return;
1.26 + }
1.27 Sum s = new Sum();
1.28 int res = Bodies.sumIndirect(s);
1.29 assert res == 42 : "Expecting 42";
1.30 @@ -65,11 +67,15 @@
1.31 }
1.32
1.33 @KOTest public void holdObjectAndReleaseObject() throws InterruptedException {
1.34 + if (ref != null) {
1.35 + assertGC(ref, "Can disappear!");
1.36 + return;
1.37 + }
1.38 Sum s = new Sum();
1.39 Object obj = Bodies.instance(0);
1.40 Bodies.setX(obj, s);
1.41
1.42 - Reference<?> ref = new WeakReference<Object>(s);
1.43 + ref = new WeakReference<Object>(s);
1.44 s = null;
1.45 assertNotGC(ref, "Cannot disappear!");
1.46
1.47 @@ -79,7 +85,7 @@
1.48 }
1.49
1.50 private static void assertGC(Reference<?> ref, String msg) throws InterruptedException {
1.51 - for (int i = 0; i < 100; i++) {
1.52 + for (int i = 0; i < 25; i++) {
1.53 if (ref.get() == null) {
1.54 return;
1.55 }
1.56 @@ -91,7 +97,7 @@
1.57 err.printStackTrace();
1.58 }
1.59 }
1.60 - throw new OutOfMemoryError(msg);
1.61 + throw new InterruptedException(msg);
1.62 }
1.63
1.64 private static void assertNotGC(Reference<?> ref, String msg) throws InterruptedException {