sclass TestPhantomCleanUp { settable bool withGC = true; settable double maxWait = 60.0; // how many seconds gettable bool referenceWasCleared; gettable Duration delayBeforeClearance; run { temp new RunnablesReferenceQueue queue; class MyPhantomRef extends PhantomReference is Runnable { new Flag flag; *(A a, RunnablesReferenceQueue queue) { super(a, queue!); } run { print("Behold the phantom!"); flag.raise(); } } var ref = new MyPhantomRef(new S("copy of a string"), queue); if (withGC) { print("GC."); timedGC(); } long time = sysNow(); printWithMS("Now waiting..."); if (ref.flag.waitUntilUp(toMS_int(maxWait))) { delayBeforeClearance = msToDuration(sysNow()-time); referenceWasCleared = true; printWithMS("Cool! Reference was cleared after " + renderElapsedSecondsPleasantly(delayBeforeClearance) + " (" + withOrWihout(withGC) + " GC)"); } else printWithMS("Ouch. Reference not cleared even after " + maxWait + " s"); } svoid allTests { new TestPhantomCleanUp().withGC(true).run(); new TestPhantomCleanUp().run(); } }