我正在为用 Java 编写的应用程序分配最多 8GB 的内存。内存不足。我相信默认情况下,新生代总是小于老年代(堆的 1/4)。而Eden/survivor 1,2在年轻代里面。我相信新对象是在伊甸园空间中创建的。
即使老年代没有满,但年轻一代已经满了,java应用程序是否仍然内存不足?
如果短生命周期对象多于长生命周期对象,是否可以为年轻代分配更多内存或至少 50% 的堆分配给年轻代?或者由于 jvm 维护,它应该总是堆的 1/4?
最佳答案
首先,1/4
似乎是另一回事。这就是分配给堆的内存量,除非您指定-Xmx
(当您在容器中时和启用的标志有点不同)。
Does the java application still go out of memory even though the old generation is not full, but the young generation is completely full?
没有。当年轻的 Eden
已满时,来自该区域的 Activity 对象被移动到 Survivor
,当来自 Survivor 的对象“存活”了足够多的 GC 周期时,它们被移动到旧区域(由XX:MaxTenuringThreshold
).当年老代达到一定限度时(IHOP
in G1
),就会发生触及年老代的 GC 周期。一些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?
young 区域越大,停顿时间越长。年轻的 GC 周期总是停止世界的事件,所以让它们太大是不好的。除此之外,这会影响你的 -XX:MaxGCPauseMillis
;并且也不要自己这样做:默认情况下 G1 GC will adjust regions as it finds most appropriate to .
关于java - JVM——新生代和老年代的比例/分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59993585/