zoukankan      html  css  js  c++  java
  • Java Memory Basic

    转自: http://www.blogjava.net/justinchen/archive/2009/justinchen/archive/2009/01/08/248738.html

    GC and Full GC

    The garbage collector (GC) detects garbage, defined as objects that are no longer reachable, then reclaims it and makes space available to the running program. The GC typically works in a stop-the-world fashion -- that is, it freezes the heap when working.

    The above diagram describes the layout of HotSpot VM Heap and it consists of three parts: perm generation, old generation and new/yang generation. The perm generation is basically for class loading. Next are the old and young generation. The young generation is further broken up into three spaces: Eden, Survivor Space 1 (SS#1) and Survivor Space 2 (SS#2). 

    Garbage Collection1. When you have a new object, the object gets created in Eden space.
    2. So after running for a while, Eden space will fill up.a minor garbage collection occurs, in which all the objects alive in Eden are copied over to SS#1. Eden is then empty and ready to receive new objects.
    3. After the minor GC, objects are allocated to Eden again. After a time, the Eden space fills up again, and another minor GC occurs. The objects surviving in SS#1 and Eden are copied to SS#2, and both SS#1 and Eden are reset. Although objects are frequently recopied, either from Eden or from one SS to another, at any one time, only Eden and one SS are operating.
    4. Every time an object moves from Eden to SS or from one SS to another, a counter and its header is incremented. By default, if the copying occurs 16 times or more, the HotSpot VM stops copying them and moves them to the old generation.
    5. If an object can't be created in Eden, it goes directly to the old generation. Moving an object from SS to the old generation because of its age is called tenuring. Because of tenuring, the old generation becomes full over time. This calls for garbage collection of the old generation, which is called a full GC. A full GC is a compaction process that is slower than a minor GC.
  • 相关阅读:
    5 float f = 3.4,是否正确
    4 String是基本数据类型吗
    3 访问修饰符public,private,protected以及不写(默认)时的区别
    1 请谈谈面向对象的三大特征?
    接口和抽象类有什么区别
    2 Java中 == 和 equals 和 hashCode 的区别
    java中重载(overload)与重写(override)的区别
    servlet中请求转发(forword)和重定向(redirect)的区别
    团队-项目名称五子棋-团队一阶段互评
    团队-项目名称五子棋-开发环境搭建过程
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3422531.html
Copyright © 2011-2022 走看看