This is a garbage collection question in java: if you allocate a large block of memory (using the new int [BIG_NUMBER] or else), is there any guarantee that the garbage collector will collect garbage before throwing OutOfMemoryError? Is this garbage collector behavior part of the Java specification now?
I found out that the garbage collector can raise this exception if it takes too long to collect garbage, at least in the case of the Java Hotspot Java Virtual Machine
"A parallel / parallel collector will raise an OutOfMemoryError if too much time is spent collecting garbage: if more than 98% of the total time is spent collecting garbage and less than 2% of the heap is recovered, OutOfMemoryError will be thrown. This function is designed to prevent applications from running for a long period time, and almost nothing happens, because the heap is too small. If necessary, this function can be disabled by adding the -XX: -UseGCOverheadLimit parameter to the command line. "
but this can be disabled, according to the quotation, by adding an option to the line command.
John donn
source share