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>

转载于:https://www.cnblogs.com/rmcary/archive/2012/11/28/2793323.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值