how does weakhashmap work?

This question already has an answer here:

  • When would you use a WeakHashMap or a WeakReference? 10 answers

  • You must not use String literals with WeakHashMap (well you can but there would be no point in it):

    String myKey = "somekey";
    

    instead you must use:

    String myKey = new String("somekey");
    

    In the latter case String is not pooled.


    The word 'obsolete' is imprecise. The condition in question is 'garbage-collected'. A value is removed from the WeakHashMap when and if the key is garbage-collected. Period.

    链接地址: http://www.djcxy.com/p/48854.html

    上一篇: iPhone中的蓝牙编程

    下一篇: weakhashmap如何工作?