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