Tabnine Logo
MemoryCache.trimMemory
Code IndexAdd Tabnine to your IDE (free)

How to use
trimMemory
method
in
com.bumptech.glide.load.engine.cache.MemoryCache

Best Java code snippets using com.bumptech.glide.load.engine.cache.MemoryCache.trimMemory (Showing top 5 results out of 315)

origin: bumptech/glide

/**
 * Clears some memory with the exact amount depending on the given level.
 *
 * @see android.content.ComponentCallbacks2#onTrimMemory(int)
 */
public void trimMemory(int 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);
 arrayPool.trimMemory(level);
}
origin: bumptech/glide

@Test
public void testTrimMemory() {
 Glide glide =
   new GlideBuilder()
     .setBitmapPool(bitmapPool)
     .setMemoryCache(memoryCache)
     .build(context);
 final int level = 123;
 glide.trimMemory(level);
 verify(bitmapPool).trimMemory(eq(level));
 verify(memoryCache).trimMemory(eq(level));
}
origin: guolindev/giffun

/**
 * Clears some memory with the exact amount depending on the given level.
 *
 * @see android.content.ComponentCallbacks2#onTrimMemory(int)
 */
public void trimMemory(int 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);
}
origin: bumptech/glide

@Test
public void testPreventEviction() {
 final MemoryCache cache = new LruResourceCache(100);
 final Resource<?> first = getResource(30);
 final Key firstKey = new MockKey();
 cache.put(firstKey, first);
 Resource<?> second = getResource(30);
 Key secondKey = new MockKey();
 cache.put(secondKey, second);
 Resource<?> third = getResource(30);
 Key thirdKey = new MockKey();
 cache.put(thirdKey, third);
 cache.setResourceRemovedListener(new ResourceRemovedListener() {
  @Override
  public void onResourceRemoved(@NonNull Resource<?> removed) {
   if (removed == first) {
    cache.put(firstKey, first);
   }
  }
 });
 // trims from 100 to 50, having 30+30+30 items, it should trim to 1 item
 cache.trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
 // and that 1 item must be first, because it's forced to return to cache in the listener
 @SuppressWarnings("unchecked")
 LruCache<Key, Resource<?>> lruCache = (LruCache<Key, Resource<?>>) cache;
 assertTrue(lruCache.contains(firstKey));
 assertFalse(lruCache.contains(secondKey));
 assertFalse(lruCache.contains(thirdKey));
}
origin: mozilla-tw/Rocket

/**
 * Clears some memory with the exact amount depending on the given level.
 *
 * @see android.content.ComponentCallbacks2#onTrimMemory(int)
 */
public void trimMemory(int 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);
 arrayPool.trimMemory(level);
}
com.bumptech.glide.load.engine.cacheMemoryCachetrimMemory

Javadoc

Trim the memory cache to the appropriate level. Typically called on the callback onTrimMemory.

Popular methods of MemoryCache

  • getMaxSize
    Returns the current maximum size in bytes of the cache.
  • clearMemory
    Evict all items from the memory cache.
  • getCurrentSize
    Returns the sum of the sizes of all the contents of the cache in bytes.
  • put
    Add bitmap to the cache with the given key.
  • remove
    Removes the value for the given key and returns it if present or null otherwise.
  • setResourceRemovedListener
    Set the listener to be called when a bitmap is removed from the cache.
  • setSizeMultiplier
    Adjust the maximum size of the cache by multiplying the original size of the cache by the given mult

Popular in Java

  • Creating JSON documents from java classes using gson
  • getSupportFragmentManager (FragmentActivity)
  • putExtra (Intent)
  • startActivity (Activity)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now