# Allocator

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/upstream/Allocator.java+class:androidx.media3.exoplayer.upstream.Allocator)

*** ** * ** ***


```
@UnstableApi
public interface Allocator
```

<br />

Known direct subclasses [DefaultAllocator](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/DefaultAllocator)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/DefaultAllocator` | Default implementation of `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator`. |

*** ** * ** ***

A source of allocations.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator.AllocationNode` A node in a chain of `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#allocate()()` Obtain an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#getIndividualAllocationLength()()` Returns the length of each individual `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#getTotalBytesAllocated()()` Returns the total number of bytes currently allocated. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocation)(https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation allocation)` Releases an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` back to the allocator. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocator.AllocationNode)(https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator.AllocationNode allocationNode)` Releases all `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` in the chain starting at the given `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator.AllocationNode`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#trim()()` Hints to the allocator that it should make a best effort to release any excess `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`. |

## Public methods

### allocate

```
abstract Allocation allocate()
```

Obtain an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`.

When the caller has finished with the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`, it should be returned by calling `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocation)`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` | The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`. |

### getIndividualAllocationLength

```
abstract int getIndividualAllocationLength()
```

Returns the length of each individual `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`.

### getTotalBytesAllocated

```
abstract int getTotalBytesAllocated()
```

Returns the total number of bytes currently allocated.

### release

```
abstract void release(Allocation allocation)
```

Releases an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` back to the allocator.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation allocation` | The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` being released. |

### release

```
abstract void release(Allocator.AllocationNode allocationNode)
```

Releases all `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation` in the chain starting at the given `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator.AllocationNode`.

Implementations must not make memory allocations.

### trim

```
abstract void trim()
```

Hints to the allocator that it should make a best effort to release any excess `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocation`.