public class

BitmapPool

extends BasePool<V>
java.lang.Object
   ↳ com.facebook.imagepipeline.memory.BasePool<V>
     ↳ com.facebook.imagepipeline.memory.BitmapPool

Class Overview

Manages a pool of bitmaps. This allows us to reuse bitmaps instead of constantly allocating them (and pressuring the Java GC to garbage collect unused bitmaps).

The pool supports a get/release paradigm. get() allows for a bitmap in the pool to be reused if it matches the desired dimensions; if no such bitmap is found in the pool, a new one is allocated. release() returns a bitmap to the pool.

Summary

Public Constructors
BitmapPool(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker)
Creates an instance of a bitmap pool.
Protected Methods
Bitmap alloc(int size)
Allocate a bitmap that has a backing memory allocacation of 'size' bytes.
void free(Bitmap value)
Frees the bitmap
int getBucketedSize(int requestSize)
Gets the bucketed size (typically something the same or larger than the requested size)
int getBucketedSizeForValue(Bitmap value)
Gets the bucketed size of the value.
int getSizeInBytes(int bucketedSize)
Gets the size in bytes for the given bucketed size
boolean isReusable(Bitmap value)
Determine if this bitmap is reusable (i.e.) if subsequent get(int) requests can use this value.
[Expand]
Inherited Methods
From class com.facebook.imagepipeline.memory.BasePool
From class java.lang.Object
From interface com.facebook.common.memory.MemoryTrimmable
From interface com.facebook.common.memory.Pool
From interface com.facebook.common.references.ResourceReleaser

Public Constructors

public BitmapPool (MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker)

Creates an instance of a bitmap pool.

Parameters
memoryTrimmableRegistry the memory manager to register with
poolParams pool parameters

Protected Methods

protected Bitmap alloc (int size)

Allocate a bitmap that has a backing memory allocacation of 'size' bytes. This is configuration agnostic so the size is the actual size in bytes of the bitmap.

Parameters
size the 'size' in bytes of the bitmap
Returns
  • a new bitmap with the specified size in memory

protected void free (Bitmap value)

Frees the bitmap

Parameters
value the bitmap to free

protected int getBucketedSize (int requestSize)

Gets the bucketed size (typically something the same or larger than the requested size)

Parameters
requestSize the logical request size
Returns
  • the 'bucketed' size

protected int getBucketedSizeForValue (Bitmap value)

Gets the bucketed size of the value. We don't check the 'validity' of the value (beyond the not-null check). That's handled in isReusable(Bitmap)

Parameters
value the value
Returns
  • bucketed size of the value

protected int getSizeInBytes (int bucketedSize)

Gets the size in bytes for the given bucketed size

Parameters
bucketedSize the bucketed size
Returns
  • size in bytes

protected boolean isReusable (Bitmap value)

Determine if this bitmap is reusable (i.e.) if subsequent get(int) requests can use this value. The bitmap is reusable if - it has not already been recycled AND - it is mutable

Parameters
value the value to test for reusability
Returns
  • true, if the bitmap can be reused