新生代、老年代

转载自:http://www.360doc.com/content/12/1023/16/9615799_243296263.shtml

1. Java堆中各代分布:(注意该图最后的Permanent区域不属于堆)


图1:Java堆中各代分布

Young:主要是用来存放新生的对象。

Old:主要存放应用程序中生命周期长的内存对象。

Permanent:是指内存的永久保存区域,主要存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域. 它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。


一般在网上查到的JVM的Heap划分:

  • Eden Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
其中Eden Space即是图中的Eden,Survivor Space即是图中的Survivor,Tenured Generation即是图中的Old。

另外,还有一个Non-heap区域:

  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
 这是图中的Permanent,有的书中也称为方法区,不属于堆的组成部分。


2. JVM 使用的GC算法是什么?

分代收集。

即将内存分为几个区域,将不同生命周期的对象放在不同区域里;

在GC收集的时候,频繁收集生命周期短的区域(Young area);

比较少的收集生命周期比较长的区域(Old area);

基本不收集的永久区(Perm area)。

 

3. GC 和 Full GC 有什么区别?

GC(或Minor GC):收集 生命周期短的区域(Young area)。

Full GC (或Major GC):收集生命周期短的区域(Young area)和生命周期比较长的区域(Old area)对整个堆进行垃圾收集。

他们的收集算法不同,所以使用的时间也不同。 GC 效率也会比较高,我们要尽量减少 Full GC 的次数。 当显示调用System.gc() 时,gc does a full collection(both young generation and tenured generation).

 

4. Minor GC后,Eden是空的吗?

是的,Minor GC会把Eden中的所有活的对象都移到Survivor区域中,如果Survivor区中放不下,那么剩下的活的对象就被移到Old generation 中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值