????WeakHashMap?????????е?expungeStaleEntries()???????????????з????б????á??????????ReferenceQueue???????Ч???????Map???????


private void expungeStaleEntries() {
         Entry<K??V> e;
         while ( (e = (Entry<K??V>) queue.poll()) != null) {
             int h = e.hash;
             int i = indexFor(h?? table.length);
 
             Entry<K??V> prev = table[i];
             Entry<K??V> p = prev;
             while (p != null) {
                 Entry<K??V> next = p.next;
                 if (p == e) {
                     if (prev == e)
                         table[i] = next;
                     else
                         prev.next = next;
                     e.next = null;  // Help GC
                     e.value = null; //  "   "
                     size--;
                     break;
                 }
                 prev = p;
                 p = next;
             }
         }
     }


????3???????????????

????WeakHashMap??Key?????????Value?????

????WeakHashMap???????????Ч???????????????????expungeStaleEntries()????з???????????????????

????4?????????????


public static void main(String args[]) {
         WeakHashMap<String?? String> map = new WeakHashMap<String?? String>();
         map.put(new String("1")?? "1");
         map.put("2"?? "2");
         String s = new String("3");
         map.put(s?? "3");
         while (map.size() > 0) {
             try {
                 Thread.sleep(500);
             } catch (InterruptedException ignored) {
             }
             System.out.println("Map Size:"+map.size());
             System.out.println(map.get("1"));
             System.out.println(map.get("2"));
             System.out.println(map.get("3"));
             System.gc();
         }
     }


???????н?????


Map Size:3
1
2
3
Map Size:2
null
2
3
Map Size:2
null
2
3
?????????


????????String?????????“2”?????????????е????????б??????