Class BitmapPool
-
- All Implemented Interfaces:
public final class BitmapPoolA thread-safe pool of reusable Bitmap objects to reduce allocation overhead during screen recording.
The pool maintains a maximum number of bitmaps based on device memory availability:
Standard devices: 3 bitmaps
Low-RAM devices: 2 bitmaps
This helps prevent excessive memory usage while still providing performance benefits from bitmap reuse.
Thread Safety: All methods are thread-safe and can be called from any thread.
-
-
Constructor Summary
Constructors Constructor Description BitmapPool(Context context)
-
Method Summary
Modifier and Type Method Description final Bitmapacquire(Integer width, Integer height)Acquires a Bitmap from the pool or creates a new one if no match is found. final Unitrelease(Bitmap bitmap)Releases a Bitmap back to the pool for reuse. final Unitclear()Clears the pool, recycling all pooled bitmaps. -
-
Constructor Detail
-
BitmapPool
BitmapPool(Context context)
-
-
Method Detail
-
acquire
final Bitmap acquire(Integer width, Integer height)
Acquires a Bitmap from the pool or creates a new one if no match is found.
Searches the pool for a bitmap matching the requested dimensions. Non-matching bitmaps remain in the pool for future use.
- Parameters:
width- The desired width of the bitmapheight- The desired height of the bitmap- Returns:
A Bitmap ready for use, or null if allocation fails (e.g., OutOfMemoryError)
-
release
final Unit release(Bitmap bitmap)
Releases a Bitmap back to the pool for reuse.
If the pool is at maximum capacity, the bitmap will be recycled instead.
- Parameters:
bitmap- The bitmap to release
-
-
-
-