简体   繁体   English

Heap中新生代和老年代的区别

[英]difference between new generation and tenured generation in Heap

I have read that new generation stores newly created objects while tenured generation stores object which survives.我读过新一代存储新创建的对象,而老一代存储存活的对象。 But I have a doubt that how will compiler know that particular object will survive or not?但我怀疑编译器如何知道特定对象是否会存活? When will it put particular object in tenured generation?什么时候将特定对象放入年老代? Please guide me.请指导我。

The young generation is divided into 3 spaces.年轻代分为3个空间。

  • One Eden space一伊甸空间
  • Two Survivor spaces两个幸存者空间

There are 3 spaces in total, two of which are Survivor spaces.总共有3个空间,其中两个是Survivor空间。 The order of execution process of each space is as below:每个空间的执行过程顺序如下:

  1. The majority of newly created objects are located in the Eden space.大多数新创建的对象都位于 Eden 空间中。
  2. After one GC in the Eden space, the surviving objects are moved to one of the Survivor spaces.在 Eden 空间中进行一次 GC 后,将幸存的对象移动到 Survivor 空间之一。
  3. After a GC in the Eden space, the objects are piled up into the Survivor space, where other surviving objects already exist.在 Eden 空间进行一次 GC 后,对象被堆积到 Survivor 空间中,该空间已经存在其他幸存的对象。
  4. Once a Survivor space is full, surviving objects are moved to the other Survivor space.一旦 Survivor 空间已满,幸存的对象就会移动到另一个 Survivor 空间。 Then, the Survivor space that is full will be changed to a state where there is no data at all.然后,已满的 Survivor 空间将变为完全没有数据的状态。
  5. The objects that survived these steps that have been repeated a number of times are moved to the old generation.在重复多次的这些步骤中幸存下来的对象被移动到老年代。

The information is taken from this article .信息取自这篇文章 I'd suggest to read it for deeper understanding.我建议阅读它以加深理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM