Tuesday, September 23, 2014

Android - Calculate optimized cache size

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

// This is how hard of a memory limit we should impose on ourselves to let system work best
// Typical values are 48MB on Nexus S, 64MB on Galaxy Nexus
int memoryClassBytes = am.getMemoryClass() * 1024 * 1024;

// Let's take only 10% of it for caching
int optimizedCacheSize = memoryClassBytes / 10;

No comments:

Post a Comment