staticvoid waitForAFinalizer() {
String s = Integer.toString(1);
BigObject b = new BigObject (s);
b = null; // Drop the object, creating garbage...
System.gc();
System.runFinalization();
// Now, we have to make sure the finalizer // gets run. We will keep allocating more // and more memory with the idea that eventually, // the memory occupied by the BigObject will get reclaimed // and the finalizer will be run.
List holdAlot = new ArrayList(); for (int chunk=10000000; chunk > 10000; chunk = chunk / 2) { if (finalizerRun) { return;
} try { while(true) {
holdAlot.add(newbyte[chunk]);
System.err.println("Allocated " + chunk);
}
} catch ( Throwable thrown ) { // OutOfMemoryError
System.gc();
}
System.runFinalization();
} return; // not reached
}
publicstaticvoid main(String[] args) throws Exception { /* *SpininwaitForAFinalizer()whilewaitingfor *anotherthreadtorunthefinalizerononeofthe *BigObjects...
*/
waitForAFinalizer();
}
} ///// End of debuggee
publicclass FinalizerTest extends TestScaffold {
publicstaticvoid main(String args[]) throws Exception { new FinalizerTest (args).startTests();
}
public FinalizerTest (String args[]) { super(args);
}
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.