为什么老年代gc比年轻代的gc久

作者: holysu | 来源:发表于2021-04-14 08:50 被阅读0次

转自 https://stackoverflow.com/questions/34670751/why-gc-on-old-generation-takes-longer-than-gc-on-young-generation

主要是两点:
- 年轻代的对象通常比较小、存活时间非常短,需要频繁回收 -> 时间优先
- 而老年代的对象相对来说比较大、存活时间长、是慢慢增长的,回收次数不频繁 -> 空间优先

When garbage collection happens memory is divided into generations, i.e. separate pools holding objects of different ages. Almost all most used configurations uses two generations, one for young objects (Young Generation) and one for old objects (Old Generation)

Different algorithms can be used to perform garbage collection in the different generations, each algorithm optimized based on commonly observed characteristics for that particular generation.

Generational garbage collection exploits the following observations, known as the weak generational hypothesis, regarding applications written in several programming languages, including the Java programming language:

• Most allocated objects are not referenced (considered live) for long, that is, they die young.
• Few references from older to younger objects exist.

Young generation collections occur relatively frequently and are efficient and fast because the young generation space is usually small and likely to contain a lot of objects that are no longer referenced.

Objects that survive some number of young generation collections are eventually promoted, or tenured, to the old generation.

image

This generation is typically larger than the young generation and its occupancy grows more slowly. As a result, old generation collections are infrequent, but take significantly longer to complete.

The garbage collection algorithm chosen for a young generation typically puts a premium on speed, since young generation collections are frequent.

On the other hand, the old generation is typically managed by an algorithm that is more space efficient, because the old generation takes up most of the heap and old generation algorithms have to work well with low garbage densities.

oracle 内存管理白皮书: https://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf

相关文章

  • 论GC

    几个名词 Minor GC——年轻代中的GC操作 Full GC——老年代中的GC操作 几种引用 强引用(Stro...

  • 为什么老年代gc比年轻代的gc久

    转自 https://stackoverflow.com/questions/34670751/why-gc-on...

  • 垃圾回收的整个过程

    过程描述 优先在eden分配 大对象直接进去老年代 年轻代分配失败 进行minor gc minor gc前会 老...

  • Java常见问题分析(内存溢出、内存泄露、线程阻塞等)

    Java垃圾回收机制(GC) 1.1GC机制作用 1.2堆内存3代分布(年轻代、老年代、持久代) 1.3GC分类 ...

  • GC

    Minor GC:从年轻代空间(包括 Eden 和 Survivor 区域)回收内存;Major GC:清理老年代...

  • 触发JVM进行Full GC的情况及应对策略

    从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC,对老年代GC称为Maj...

  • JVM学习笔记

    1. young GC 和 full GC young gc:回收年轻代垃圾,回收频繁,速度较快 full gc:...

  • JVM-GC日志分析

    全量GC日志 分段分析(一) GC发生时间 GC 或 Full GC 表示垃圾收集器停顿类型,新生代GC还是老年代...

  • PFI

    jvm 介绍下内存模型?为什么需要内存模型?新生代gc方式?工作原理? 老年代GC方式?工作原理?适用场景? 标...

  • Java GC日志分析

    1. 查看GC日志准备 2. 年轻代GC日志 3. CMS GC日志 4. CMS GC 7阶段解析 1.初始标记...

网友评论

    本文标题:为什么老年代gc比年轻代的gc久

    本文链接:https://www.haomeiwen.com/subject/nubdkltx.html