** What is java.lang.OutOfMemoryError: Java heap space means ** This mesasge means when an application just requires more Java heap space than is available for it to work properly.
That java.lang.OutOfMemoryError exceeded the upper limit of GC, means
This message means that for some reason the garbage collector takes too much time (98% of the total process time by default) and restores very little memory in each run (default 2% of the heap). This internally also means that when an application simply requires more Java heap space than is available for it to work properly.
So my question is, which scenario of the two above will trigger?
So here is my understanding when a particular exception will be selected based on the scenario: -
Let's say I allocated 1 GB of heap size. Currently, 970 MB of memory is used. A thread has begun (the JVM does not know in advance how much memory it will consume). GC can now take one of the following steps
1) The JVM starts allocating memory, and then at one point in time it gives out 1 GB of memory and throws "java.lang.OutOfMemoryError: Java heap space" means
2) The GC starts in advance and tries to free some memory because it knows that the memory currently in use is close to 1 GB allocated by Heap. But it cannot free up more than 2% of the space in each subsequent run. Then it will be throwjava.lang.OutOfMemoryError: GC` upper limit is exceeded
As far as I understand in the context of my question?
source
share