staticclass WeakRef {
ReferenceQueue<Object> queue = new ReferenceQueue<Object>(); finalint numReferences = 100; final Reference refs[] = new Reference[numReferences]; finalint iterations = 1000;
void run() throws InterruptedException { for (int i = 0; i < iterations; i++) {
queue = new ReferenceQueue<Object>();
for (int j = 0; j < refs.length; j++) {
refs[j] = new WeakReference(new Object(), queue);
}
System.gc(); // enqueues references into the list of discovered references
// now manually enqueue all of them for (int j = 0; j < refs.length; j++) {
refs[j].enqueue();
} // and get them back. There should be exactly numReferences // entries in the queue now. int foundReferences = 0; while (queue.poll() != null) {
foundReferences++;
}
if (foundReferences != refs.length) { thrownew RuntimeException("Got " + foundReferences + " references in the queue, but expected " + refs.length);
}
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.