problem about linkedhashmap-Collection of common programming errors


  • Passionate programmer

  • weakwire
    java android serialization linkedhashmap
    So i want to pass a LinkedHashMap to an intent.//SEND THE MAP Intent singlechannel = new Intent(getBaseContext(),singlechannel.class); singlechannel.putExtra(“db”,shows1);//perase to startActivity(singlechannel);//GET THE MAP LinkedHashMap<String,String> db = new LinkedHashMap<String,String>(); db=(LinkedHashMap<String,String>) getIntent().getSerializableExtra(“db”);This one Worked Like a charm with HashMap. But with LinkedHashMap i got a problem i got a runtime error heredb

  • Nearalias
    java runtime implementation linkedhashmap
    So I’ve looked around a little and couldn’t really find any straight up answer for this. Personally I’m guessing Java probably manipulates timestamp on the items inserted into the LinkedHashMap, and possibly uses that in its ordering somehow.I know that all the removeEldestEntry needs to do is simply returning true/false, but then when it gets to actually removing the eldest entry from the map, it would seem like the runtime would be O(n), what is it really?Thanks.

  • wziska
    java caching memory-leaks linkedhashmap
    I’m trying to use LinkedHashMap as a local FIFO cache solution overwriting its removeEldestEntry method to keep size fixed:Map lhm = new LinkedHashMap(MAX_CACHE_SIZE + 1, .75F, false) {protected boolean removeEldestEntry(Map.Entry eldest) {return size() > MAX_CACHE_SIZE;} };but when I constantly add new entries to the map monitoring process memory I see it keeps growing until max virtual machine memory is used though map size doesn’t increase.Is it by design? Why does it need more memory if o