Genia S. Genia S. - 23 days ago 9
Android Question

Is the LruCache constrained by the Android app memory space?

I'm looking at the docs and trying to understand if the LruCache is competing for heap resources with the rest of my app or if it's actually using some sort of elaborate disk swapping mechanism.

The reason I'm asking is that I want to allocate a lot of memory for the cache (say a gig) so that if the device loses its Internet connectivity a large amount of image data can persis locally. However, if the LruCache is constrained by the size of the App's heap memory allotment this obviously won't work.

I'm hoping someone can point me to more detailed documentation about how this feature works and if this *isn't the right feature to handle this need, if I need to roll my own or if there's an Android native disk swap memory class that I'm overlooking that maybe should be combined with LruCache (or used entirely on its own?)

Answer

I'm looking at the docs and trying to understand if the LruCache is competing for heap resources with the rest of my app or if it's actually using some sort of elaborate disk swapping mechanism.

It is using heap space of your app. You can see the LRUCache source code to confirm this.

However, if the LruCache is constrained by the size of the App's heap memory allotment this obviously won't work.

Correct.

if I need to roll my own or if there's an Android native disk swap memory class that I'm overlooking

There is really no concept of "disk swap memory" at the Android app level, and very few devices even implement it at the OS level.