private static final Runtime rt = Runtime.getRuntime();
static void gcTillYouDrop() {
rt.gc();
rt.runFinalization();
final CountDownLatch latch = new CountDownLatch(1);
new Object() {
protected void finalize() {
latch.countDown();
}
};
rt.gc();
try {
latch.await();
}
catch(InterruptedException ie){
throw new Error(ie);
}
}
"Hyper-paranoid" indeed, in the words of Kevin.