有关垃圾回收内部的一些问题? [英] some questions on Garbage Collection internals?

查看:79
本文介绍了有关垃圾回收内部的一些问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图了解垃圾收集流程的工作方式.遇到了很好的链接. 大多数文章说,在次要GC收集期间,对象从伊甸园移到幸存者空间,而在主要GC收集期间 对象将从幸存者移至保管空间,否则将回收所有无法访问的对象内存.我有三个问题(需要问 根据上述陈述,立即进行相关操作:-

I am trying to understand how Garbage collection process works. Came across good link . Most of the articles says that during minor GC collection object is moved from eden to survivor space and during major GC collection object is moved from survivor to tenured space otherwise all unreachable objects memory is reclaimed. I have three questions(need to ask in single go as they are related) based on above statements :-

1)Minor vs Major GC collection ? What is the difference between two that one is called major and other is called minor collection? 根据我的理解,次要收集与应用程序运行并行发生,而主要收集使应用程序运行 在此期间暂停.

1)Minor vs Major GC collection ? What is the difference between two that one is called major and other is called minor collection? As per my understanding during minor collection happens in parallel to application run while major collection makes application to pause during that period.

2)What actually happens when object is moved from eden to survivor space ? Does the memory location of object is changed internally?

3)Why not just one space exist instead of three i.e eden, survivor and tenured space exist ?我知道背后一定有一个原因,但我很想念它. 我的意思是,GC运行时,收集无法访问的对象并将仅可访问的对象留在该空间中.仅一个空间就足够了.那么三种不同的优势是什么 空间证明一个以上?

3) Why not just one space exist instead of three i.e eden, survivor and tenured space exist ? I know there is must be a reason behind it but i am missing it. My point is when GC runs , collect unreachable object and leaves the reachable ones in that space only. Just one space seems to be sufficient. So what advantage three different spaces are proving over one?

推荐答案

1)次要GC发生在新一代,主要GC发生在老一代.是否与应用程序并行取决于GC的类型,只有CMS和G1可以同时工作

1) Minor GC occurs on new generation, major GC occurs on old generation. Whether it is parallel to the application or not depends on the kind of GC, only CMS and G1 can work concurrently

2)是的,GC期间移动的对象会更改其物理位置,因此将更新指向该对象的所有指针

2) Yes, moving object during GC changes its physical location so all pointers to this object will be updated

3)这是为了避免GC期间应用程序长时间冻结.如果是一大堆,则应用程序通常会冻结很长时间. JVM在年轻的一代中创建对象,其中的GC频繁但快速地发生.由JVM创建的大多数对象很快就会死掉,并且永远都不会消失,因此大型GC很少发生,或者根本不会发生.

3) This is to avoid often and long application freezing during GC. If it was one big heap then application would often freeze for long periods of time. JVM creates objects in small young generation, GCs in it occur frequently but quickly. Most objects created by JVM die quickly and they never get to old generation, so major GC happens rarily or it may never happen at all.

这篇关于有关垃圾回收内部的一些问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆