JAVA GC Major GC vs Minor GC

空扰寡人 提交于 2021-01-27 13:45:12

问题


In our latency sensitive app we have caching data (which resides in TG) and short lived object which die out in the YG. I have seen there is significant difference in the minor GC time and Major GC time. I suspected that it is related to relatively larger size of TG. Could anyone explain how the GC time correlates with the TG size. Minor GC is quite frequent and fast.


回答1:


Objects which survive minor collection in YG gets moved to TG/Old generation to free up space in YG. Size of YG is kept small to ensure that minor collection doesn't take much time and can be run more frequently. And during these minor GC objects which still have references are moved to TG.

So TG size is more because usually bigger objects which survive few YG cleanups move to this segment. Also cleanup in TG doesn't run very frequently so it can have bigger memory allocated.

So minor GC cleans up objects in YG but major GC cleans up YG as well as TG.




回答2:


The main point is that GC time is dictated not by the TG size, but by the number of objects in it. A performance-sensitive application should not use the heap for caching. There is a wide range of existing caching libraries that support off-heap caches.



来源:https://stackoverflow.com/questions/13642241/java-gc-major-gc-vs-minor-gc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!