This is a question about garbage collection in java: if one allocates a large block of memory (using new int[BIG_NUMBER] or however), is there any guarantee that a garbage collector will collect the garbage before an OutOfMemoryError is thrown? Is this behaviour of garbage collector a part of the Java spec by now?
I have learnt that a garbage collector itself might throw such exception in case it takes too long to collect the garbage, at least in the case of Sun Hotspot Java Virtual Machine
«The parallel / concurrent collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line. »
but this may be disabled, according to the citation, by adding an option to the command line.