Reputation: 2338
I am allocating 8GB memory for max to the the application written in Java. It goes out of memory. I believe that young generation is always smaller than the old generation by default(1/4 of the heap). And Eden/survivor 1,2 are inside the young generation. I believe that new objects are created in Eden space.
Does the java application still go out of memory even though the old generation is not full, but the young generation is completely full?
If there are more short-lived objects than long-lived objects, is it ok to allocate more memory to the young generation or at least 50% of the heap to the young generation? Or should it be always 1/4 of the heap because of jvm maintenance?
Upvotes: 3
Views: 3509
Reputation: 120848
First of all, that 1/4
seems like a different thing. That is how much memory will be allocated to your heap, unless you specify -Xmx
(it's a bit different when you are in a container and what flags you have enabled).
Does the java application still go out of memory even though the old generation is not full, but the young generation is completely full?
No. When young Eden
is full, live Objects from that are moved to Survivor
, when those from Survivor "survive" enough GC cycles, they are moved to the old region (controlled with XX:MaxTenuringThreshold
). When old generation hits a certain limit (IHOP
in G1
), a GC cycle touching the old generation will happen. Some more details here.
If there are more short-lived objects than long-lived objects, is it ok to allocate more memory to the young generation or at least 50% of the heap to the young generation?
The bigger the young region, the longer the pauses will be. Young GC cycles are always stop-the-world events, so making them too big is not good. Besides this will effect your -XX:MaxGCPauseMillis
; and also do not do that on your own: by default G1 GC will adjust regions as it finds most appropriate to.
Upvotes: 3