Reference summary

This is what I sum up here to prove you really understand reference?

Q: what is reference and referent?

Q: what are the gc roots?

Q: during gc mark and sweep phases, how collector handle different kinds of reference?

Q: explain the interaction between gc and reference ?

Q: how apps get involved in gc lifecycle? notification?

Q: what is relation between finalizer and gc? how can finalizer pause gc process, unintentionally?

Q: when we deal with weakreference, we need to check null from get method, why? then holds strong reference to the value?

Q: what is ReferenceHandler? why handler.setPriority(Thread.MAX_PRIORITY); is this the consumer of referencequeue?

Q: then, who is the product of referencequeue? how productor and consumer sync?

Q: after you poll reference out of referencequeue, what you should do?

Q: how to reconstruct object during gc, equalskey?

Q: why weakhashmap entry overrides equals and hashcode?

Q: what is purpose of IdentityHashMap? 

Q: how to avoid reconstruct value? 

Q: why phantomReference get always return null?

Q: why not use weakreference to cache instead of softreference?

Q:when weakhashmap null its key? does it automatically null its value and entrys?

Q: how to trigger weakhashmap null stale entries? expungeStaleEntries()?

Q: detail the relationship between key, value, entry, reference in weakhashmap?

Q: explain the following method in WeakHashMap, why we don't need expunge entries? doesn't entry still hold strong reference to value?

    "cut stale values from entry link", every objects referenced only by entry will be collected! so, values will be collected.

     

    public void clear() {
// clear out ref queue. We don't need to expunge entries
// since table is getting cleared.
while (queue.poll() != null)
;

modCount++;
Arrays.fill(table, null);
size = 0;

// Allocation of array may have caused GC, which may have caused
// additional entries to go stale. Removing these entries from the
// reference queue will make them eligible for reclamation.
while (queue.poll() != null)
;
}

Q: tell me the typical poll pattern? code snippets?

 

always trace objects from gc roots. :)

 

source code links:

openjdk

 

 

 

转载于:https://www.cnblogs.com/grep/archive/2012/03/19/2406104.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值