am 6f680f52: Displaying Bitmaps Efficiently Training - Change memory calculation

* commit '6f680f524a66dabcf0d86d0f19f3855f8c5e594f':
  Displaying Bitmaps Efficiently Training - Change memory calculation
This commit is contained in:
Adam Koch
2013-01-14 06:15:20 -08:00
committed by Android Git Automerger
2 changed files with 8 additions and 7 deletions

View File

@@ -101,19 +101,20 @@ private LruCache<String, Bitmap> mMemoryCache;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
... ...
// Get memory class of this device, exceeding this amount will throw an // Get max available VM memory, exceeding this amount will throw an
// OutOfMemory exception. // OutOfMemory exception. Stored in kilobytes as LruCache takes an
final int memClass = ((ActivityManager) context.getSystemService( // int in its constructor.
Context.ACTIVITY_SERVICE)).getMemoryClass(); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// Use 1/8th of the available memory for this memory cache. // Use 1/8th of the available memory for this memory cache.
final int cacheSize = 1024 * 1024 * memClass / 8; final int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override @Override
protected int sizeOf(String key, Bitmap bitmap) { protected int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in bytes rather than number of items. // The cache size will be measured in kilobytes rather than
return bitmap.getByteCount(); // number of items.
return bitmap.getByteCount() / 1024;
} }
}; };
... ...