Jayaprakash Marshal
Jayaprakash Marshal

Reputation: 250

How to check the memory available in LruCache of android?

I want to use memory cache(LruCache) instead of DiskLruCache for caching the images. I have some doubts regarding the image Caching in android.

How can i check the available memory size in Lrucache?

What does happen when the caching request crosses the Available memory in Lrucache?

Is the LruCache object retain in dalvik heap memory? or caching done is kept in heap memory?

Upvotes: 1

Views: 682

Answers (1)

Daniele D.
Daniele D.

Reputation: 2734

Answer to first question:

    private LruCache<String, Bitmap> mMemoryCache;
    //...
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    int availMemInBytes = am.getMemoryClass() * 1024 * 1024;

Answer to the second:

The Least Recently Used object(s) will be removed from the list. One or more objects will be removed till there will be enough space to put the new object.

About the third question I think I'm late since Dalvik is not anymore used for Android > 4.4.2. Maybe this video can help to figure out what happens with the new ART https://www.youtube.com/watch?list=PLOU2XLYxmsIJDPXCTt5TLDu67271PruEk&t=47&v=R5ON3iwx78M

I hope it will help.

Upvotes: 1

Related Questions