转载自: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.
另外,还有一个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.
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 中。