当伊甸园满载而其中所有对象都是活着的时候会发生什么。

huangapple go评论70阅读模式
英文:

what will happen when eden is full but all objects in it is alive

问题

我正在学习Java内存管理,根据我已经从互联网上学到的知识。

当Eden空间满时,将触发Minor GC,Minor GC将把仍在被引用的对象复制到一个空的幸存者空间,但该空间比Eden小。当Eden装满存活对象时,收集器会做什么?据我所知,Java GC收集器是一个复制收集器,它应该将所有存活对象移开,然后清除旧的内存空间。

英文:

I am learnging Java memory management, From what I already learned from internet.

Minor GC is triggered when Eden space is full, Minor GC will copy objects still being referenced to one survivor space which is empty, but that space is smaller than Eden, What will collector do when eden is full of alive objects ? AFAIK,Java GC Collector is copying collector, it should move all live objects away then clear old memory space.

答案1

得分: 1

> 当Eden空间满时会触发小型GC。

几乎是正确的。当主要GC被触发时,也可以触发小型GC。这就像垃圾收集器说:“我需要执行一次完全GC,但首先我会执行一次小型GC”。在这种情况下(例如G1就是这样做的),Eden空间可能并不是满的。

当发生这种情况时(某些Eden区域无法完全清空时),这些区域会被标记为老年区,正如这里的注释所述:

> 未能清空的区域总是会变成老年区...

英文:

> Minor GC is triggered when Eden space is full

almost correct. A minor GC can be triggered when a major GC is triggered. It's like the GC says : "I need to do a Full GC, but first I'll do a minor one". In that case (G1 does this, for example), Eden space might not be full.

When that happens (some Eden regions could not be completely evacuated), those regions are made old, as even commented here:

> Regions that failed evacuation are always made old...

huangapple
  • 本文由 发表于 2020年9月23日 20:27:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/64027972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定