voidcleanReferenceQueue(){while(!isShutdown){try{ResourceWeakReferenceref=(ResourceWeakReference)resourceReferenceQueue.remove();cleanupActiveReference(ref);// This section for testing only.DequeuedResourceCallbackcurrent=cb;if(current!=null){current.onResourceDequeued();}// End for testing only.}catch(InterruptedExceptione){Thread.currentThread().interrupt();}}}
@NullableprivateEngineResource<?>loadFromMemory(EngineKeykey,booleanisMemoryCacheable,longstartTime){//内存缓存不可用直接返回nullif(!isMemoryCacheable){returnnull;}//先从ActiveResources中获取EngineResource<?>active=loadFromActiveResources(key);if(active!=null){if(VERBOSE_IS_LOGGABLE){logWithTimeAndKey("Loaded resource from active resources",startTime,key);}returnactive;}//如果ActiveResources中没有,则从MemoryCache中获取EngineResource<?>cached=loadFromCache(key);if(cached!=null){if(VERBOSE_IS_LOGGABLE){logWithTimeAndKey("Loaded resource from cache",startTime,key);}returncached;}returnnull;}
publicstaticfinalclassBuilder{@VisibleForTestingstaticfinalintMEMORY_CACHE_TARGET_SCREENS=2;/** * On Android O+, we use {@link android.graphics.Bitmap.Config#HARDWARE} for all reasonably * sized images unless we're creating thumbnails for the first time. As a result, the Bitmap * pool is much less important on O than it was on previous versions. */staticfinalintBITMAP_POOL_TARGET_SCREENS=Build.VERSION.SDK_INT<Build.VERSION_CODES.O?4:1;staticfinalfloatMAX_SIZE_MULTIPLIER=0.4f;staticfinalfloatLOW_MEMORY_MAX_SIZE_MULTIPLIER=0.33f;// 4MB.staticfinalintARRAY_POOL_SIZE_BYTES=4*1024*1024;@SyntheticfinalContextcontext;// Modifiable (non-final) for testing.@SyntheticActivityManageractivityManager;@SyntheticScreenDimensionsscreenDimensions;@SyntheticfloatmemoryCacheScreens=MEMORY_CACHE_TARGET_SCREENS;@SyntheticfloatbitmapPoolScreens=BITMAP_POOL_TARGET_SCREENS;@SyntheticfloatmaxSizeMultiplier=MAX_SIZE_MULTIPLIER;@SyntheticfloatlowMemoryMaxSizeMultiplier=LOW_MEMORY_MAX_SIZE_MULTIPLIER;@SyntheticintarrayPoolSizeBytes=ARRAY_POOL_SIZE_BYTES;}