Object Death in Garbage Collector's Perspective

Our program can directly access values stored in three locations - registers, stack (including local variables and temporary variables) and global variables. References stored in these locations are the so-called root set. For the memory allocated dynamically, it can only be accessed from root set or reference chains from root set. The precondition is, the program cannot access any random location in its address space.

By the time an object becomes unreachable by user program, it dies. That means the object is no longer in use by program and cannot be accessed by program from root set. Therefore the object is called garbage and will be reclaimed by collector. The memory that occupied will be returned to the heap.

The object death is actually caused by pointer update. All of the pointer update events can be divided into three simple cases.

  • In object graph (1), for object a, if the only incoming reference to object a is broken, then a dies immediately.
  • In object graph (2), for object c, it has only one incoming reference from object b. In this case, if the incoming reference to object b is broken, then c and b die immediately with object b’s death.
  • In object graph (3), for object e and f, they both can be only reached from object d. In this case, if the incoming reference to object d is broken, then d dies. Immediately, object e and f die too.

<EOF>

posted on 2012-11-28 20:01  Cary_Fan  阅读(608)  评论(0编辑  收藏  举报

导航