Search code examples
javaandroidcachingmemoryandroid-lru-cache

Getting current memory used in LRUCache Android


For testing I want to see how many kB / MB are currently in use in my LRU Cache. I have the total size set to 4096.

Is there a function like:

public LruCache<String, Bitmap> myCache;
...
...
println(myCache.getUsedAmount());

or

println(myCache.getAvailabeSpace());

Solution

  • Take a look at the Documentation.

    Using size() should work fine, if you do not override sizeOf(K,V):

    For caches that do not override sizeOf(K, V), this returns the number of entries in the cache. For all other caches, this returns the sum of the sizes of the entries in this cache.

    You may also run through all entries and check their size.