Java????????WeakHashMap
???????????? ???????[ 2012/7/30 13:10:29 ] ????????
?? ???Effective Java 2nd Edition???У???6??“????????????????”???????Java????????????????????????????????棬??t??????й??????????????????????е????????п??????????й??????????л?????????WeakHashMap????????????????????Ч???????????????????????????????????н????“??????”??????????????????Щ?????
??????Java ??????????? ?????????????й???????????????????Map?????????????????????й?????????????????hprof????????????й???????????????????????????????й???????????WeakHashMap????????????вο??????????????????????????????????????????????????????????????????????????
????1??????????
??????JDK1.2?汾??????????????÷????????????????????????????????????????????????????????????????????á??????á??????ú??????á?
?????????????????????????磺Object object=new Object????????object????????????????????????????????????????????????????????????????????????????????????? ????Java???????????OutOfMemoryError???????????????????????????????????????????????治??????
???????????SoftReference????????????????????????????????????п??????????????????????????????????????????????????????????????????Щ???????檔??????????????л??????????????????????á????????????????????е??????檔 ???????????????????У?ReferenceQueue??????????????????????????????????????Java????????????????ü????????????????????С?
???????????WeakReference????????????????????????????????????п??????????????????????????????????????????????????????и??????????????????????????????????? ???????????????????У??????????????????????????????????????????????????????檔?????????????????????????????????????? ???????????????Щ??????????????? ???????????????????У?ReferenceQueue??????????????????????????????????????Java????????????????ü????????????????????С?
???????????PhantomReference????“??????”??????壬????????裬?????????????????????????ò???????????????????????????????????????????????????????κ?????????????κ?????????????????? ?????????????????????????????????????????????ú????????????????????????????????????? ??ReferenceQueue????????á??????????????????????????????????????????????????????????????????????????????ü?????? ??????????????С????????????ж????????????????????????????????????????????????????????????????????????????????????????????У???????????????????????汻???????????????ж???
????2??WeakHashMap??????
????WeakHashMap????????ReferenceQueue???????????д????????Key????
private final ReferenceQueue<K> queue = new ReferenceQueue<K>();
????WeakHashMap.Entry<K??V>?в???б???Key??????Key??ReferenceQueue?????????
private static class Entry<K??V> extends WeakReference<K> implements Map.Entry<K??V> {
private V value;
private final int hash;
private Entry<K??V> next;
Entry(K key?? V value?? ReferenceQueue<K> queue?? int hash?? Entry<K??V> next) {
super(key?? queue);
this.value = value;
this.hash = hash;
this.next = next;
}
……
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11