Jay Snayder
Jay Snayder

Reputation: 4338

Does LruCache release entries when memory is low?

I can't quite get the memory management component of the LruCache understood fully.

In one sense I am expecting it to act as an NSCache on the iOS platform (having just picked up some knowledge from that operating system recently).

Does the LruCache release entries if the application is low on memory ?

Or if I set the maximum entries / size of the LruCache, then it will always take up room and not free it until that entry / size is reached?

I don't want a third party library that is being constructed to take away from necessary resources of the user.

How can i do this ?

Upvotes: 1

Views: 446

Answers (1)

Kaschwenk
Kaschwenk

Reputation: 622

This is a video from the 2012 Google I/O where LRU-Caches are explained (at 3:00). He further goes into the topic of what the OS does on low memory:

http://www.youtube.com/watch?v=gbQb1PVjfqM

I don't think that the OS will evict cache entries on low memory as it would steal ressources from the application that it (the app) might need. The OS will probably not know which items out of the cache are used by the application. It will kill a background app which was least recently used and / or with the highest memory consumption.
Btw: You can actively help the OS with resizing your LRU if it is low on memory by implementing the onTrim() callback. You can find further information in the youtube video and here:

http://developer.android.com/training/articles/memory.html#ReleaseMemoryAsTight

hope this helps :)

Upvotes: 1

Related Questions