use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.
the class LoadBitmapTest method transformFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap.
@Test
public void transformFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap() {
Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
concurrency.wait(GlideApp.with(context).load(bitmap).centerCrop().submit(100, 100));
assertThat(bitmap.isRecycled()).isFalse();
}
use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.
the class LoadBitmapTest method clearFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap.
@Test
public void clearFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap() {
Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
Target<Bitmap> target = concurrency.wait(GlideApp.with(context).asBitmap().load(bitmap).submit(100, 100));
Glide.with(context).clear(target);
// Allow Glide's resource recycler to run on the main thread.
concurrency.pokeMainThread();
assertThat(bitmap.isRecycled()).isFalse();
}
use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.
the class LoadBitmapTest method transformFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap.
@Test
public void transformFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap() {
Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
concurrency.wait(GlideApp.with(context).asDrawable().load(bitmap).centerCrop().submit(100, 100));
assertThat(bitmap.isRecycled()).isFalse();
}
use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.
the class CachingTest method submit_withRequestClearedFromMemory_doesNotLoadFromMemory.
@Test
public void submit_withRequestClearedFromMemory_doesNotLoadFromMemory() {
Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()));
// Allow the request to be run and GCed without being cleared.
concurrency.loadOnOtherThread(new Runnable() {
@Override
public void run() {
FutureTarget<Drawable> first = GlideApp.with(context).load(raw.canonical).submit();
concurrency.get(first);
}
});
// Wait for the weak reference to be cleared and the request to be removed from active
// resources.
// De-flake by allowing multiple tries
boolean isWeakRefCleared = false;
for (int j = 0; j < 100; j++) {
Runtime.getRuntime().gc();
concurrency.pokeMainThread();
try {
// Loading again here won't shuffle our resource around because it only changes our
// reference count from 1 to 2 and back. The reference we're waiting for will only be
// decremented when the target is GCed.
Target<Drawable> target = concurrency.wait(GlideApp.with(context).load(ResourceIds.raw.canonical).onlyRetrieveFromCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit());
GlideApp.with(context).clear(target);
} catch (RuntimeException e) {
// The item has been cleared from active resources.
isWeakRefCleared = true;
break;
}
}
if (!isWeakRefCleared) {
fail("Failed to clear weak ref.");
}
concurrency.get(GlideApp.with(context).load(ResourceIds.raw.canonical).listener(requestListener).submit());
verify(requestListener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), not(eq(DataSource.MEMORY_CACHE)), anyBoolean());
}
use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.
the class LoadDrawableTest method transform_withLoadedBitmapDrawable_doesNotRecycleBitmap.
@Test
public void transform_withLoadedBitmapDrawable_doesNotRecycleBitmap() {
Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
concurrency.wait(GlideApp.with(context).load(drawable).centerCrop().submit(100, 100));
assertThat(bitmap.isRecycled()).isFalse();
}
Aggregations