This thread, and this page:
It [
OutOfMemoryError
] will never be thrown unless the JVM tries a full garbage collection first, including removal of softly/weakly referenced objects.
As for this piece of code,
//.. allocate reserved memory
try {
//.. calculation which requires alot of memory even after optimized
} catch (java.lang.OutOfMemoryError e){
System.gc();
//.. hedge recovery
}
Is the call to System.gc()
redundant?
Is it already guaranteed that JVMs (according to JVMS) had run the GC before throwing java.lang.OutOfMemoryError
?