Android : Least recently used (LRU) algorithm implementation in java?

1.3k views Asked by At

In my application am having lot bitmaps around 1000. I have to merge them as a single image. In order to do this , loading currently needed bitmaps from sdcard .In this process i have to recyle Least recently used bitmaps other wise dvm throws out of memory error . so can any one tell me how to accomplish this task (Least recently used ) in java.??

Thank you, Srinivas

2

There are 2 answers

0
templatetypedef On BEST ANSWER

You may want to look into the LinkedHashMap or LinkedHashSet implementations in the Collections API, which provide support for a highly-configurable LRU framework.

0
Rahul Ramamoorthy On

LinkedHashMap would be perfect fit for this type of problems.removeEldestEntry() method of LinkedHashMap class returns true to remove oldest entry