public class

SharedByteArray

extends Object
implements MemoryTrimmable
java.lang.Object
   ↳ com.facebook.imagepipeline.memory.SharedByteArray

Class Overview

Maintains a shareable reference to a byte array.

When accessing the shared array proper synchronization is guaranteed. Under hood the get method acquires an exclusive lock, which is released whenever the returned CloseableReference is closed.

If the currently available byte array is too small for a request it is replaced with a bigger one.

This class will also release the byte array if it is unused and collecting it can prevent an OOM.

Summary

Public Constructors
SharedByteArray(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params)
Public Methods
CloseableReference<byte[]> get(int size)
Get exclusive access to the byte array of size greater or equal to the passed one.
void trim(MemoryTrimType trimType)
Responds to memory pressure by simply 'discarding' the local byte array if it is not used at the moment.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.common.memory.MemoryTrimmable

Public Constructors

public SharedByteArray (MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params)

Public Methods

public CloseableReference<byte[]> get (int size)

Get exclusive access to the byte array of size greater or equal to the passed one.

Under the hood this method acquires an exclusive lock that is released when the returned reference is closed.

public void trim (MemoryTrimType trimType)

Responds to memory pressure by simply 'discarding' the local byte array if it is not used at the moment.

Parameters
trimType kind of trimming to perform (ignored)