Skip to content

Commit

Permalink
Swap clearing memory cache and pool to prevent re-pooling Bitmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Oct 29, 2015
1 parent 44b41f7 commit 82b148c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ public void preFillBitmapPool(PreFillType.Builder... bitmapAttributeBuilders) {
* @see android.content.ComponentCallbacks2#onLowMemory()
*/
public void clearMemory() {
bitmapPool.clearMemory();
// Engine asserts this anyway when removing resources, fail faster and consistently
Util.assertMainThread();
// memory cache needs to be cleared before bitmap pool to clear re-pooled Bitmaps too. See #687.
memoryCache.clearMemory();
bitmapPool.clearMemory();
}

/**
Expand All @@ -376,8 +379,11 @@ public void clearMemory() {
* @see android.content.ComponentCallbacks2#onTrimMemory(int)
*/
public void trimMemory(int level) {
bitmapPool.trimMemory(level);
// Engine asserts this anyway when removing resources, fail faster and consistently
Util.assertMainThread();
// memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687.
memoryCache.trimMemory(level);
bitmapPool.trimMemory(level);
}

/**
Expand All @@ -404,6 +410,9 @@ public void clearDiskCache() {
* </p>
*/
public void setMemoryCategory(MemoryCategory memoryCategory) {
// Engine asserts this anyway when removing resources, fail faster and consistently
Util.assertMainThread();
// memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687.
memoryCache.setSizeMultiplier(memoryCategory.getMultiplier());
bitmapPool.setSizeMultiplier(memoryCategory.getMultiplier());
}
Expand Down

0 comments on commit 82b148c

Please sign in to comment.