// helper method to keep testObject and map out of main method's scope privatestatic HashMap<Integer, Object> makeMap() {
HashMap<Integer, Object> map = new HashMap<Integer, Object>();
Object testObject = new Object();
wr = new WeakReference<Object>(testObject);
map.put(42, testObject); return map;
}
publicstaticvoid main(String[] args) throws Exception {
HashMap<Integer, Object> hm = makeMap();
hm = (HashMap<Integer, Object>)hm.clone();
hm.clear(); // There should no longer be a strong reference to testObject // the WeakReference should be nulled out by GC. If not, // we will hang here until timed out by the test harness.
Object[] chain = null; while (wr.get() != null) { try {
Object[] allocate = new Object[1000000];
allocate[0] = chain;
chain = allocate;
} catch (OutOfMemoryError oome) {
chain = null;
}
System.gc(); Thread.sleep(100);
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.