1 package com.bumptech.glide.load.engine; 2 3 4 /** 5 * A resource interface that wraps a particular type so that it can be pooled and reused. 6 * 7 * @param <Z> The type of resource wrapped by this class. 8 */ 9 public interface Resource<Z> { 10 11 /** 12 * Returns an instance of the wrapped resource. 13 * <p> 14 * Note - This does not have to be the same instance of the wrapped resource class and in fact it is often 15 * appropriate to return a new instance for each call. For example, 16 * {@link android.graphics.drawable.Drawable Drawable}s should only be used by a single 17 * {@link android.view.View View} at a time so each call to this method for Resources that wrap 18 * {@link android.graphics.drawable.Drawable Drawable}s should always return a new 19 * {@link android.graphics.drawable.Drawable Drawable}. 20 * </p> 21 */ 22 Z get(); 23 24 /** 25 * Returns the size in bytes of the wrapped resource to use to determine how much of the memory cache this resource 26 * uses. 27 */ 28 int getSize(); 29 30 /** 31 * Cleans up and recycles internal resources. 32 * 33 * <p> 34 * It is only safe to call this method if there are no current resource consumers and if this method has not 35 * yet been called. Typically this occurs at one of two times: 36 * <ul> 37 * <li>During a resource load when the resource is transformed or transcoded before any consumer have 38 * ever had access to this resource</li> 39 * <li>After all consumers have released this resource and it has been evicted from the cache</li> 40 * </ul> 41 * 42 * For most users of this class, the only time this method should ever be called is during transformations or 43 * transcoders, the framework will call this method when all consumers have released this resource and it has 44 * been evicted from the cache. 45 * </p> 46 */ 47 void recycle(); 48 } 49