# Allocator

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator "View this page in Java")

<br />

```
@UnstableApi
interface Allocator
```

<br />

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

|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| [DefaultAllocator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator) | Default implementation of[Allocator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator). |

*** ** * ** ***

A source of allocations.

## Summary

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

|                                             ### Public functions                                              |
|---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)`!` | [allocate](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#allocate())`()` Obtain an[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).                                                                                                                                                                                                                                                                                                                                                                                     |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                   | [getIndividualAllocationLength](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#getIndividualAllocationLength())`()` Returns the length of each individual[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).                                                                                                                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                   | [getTotalBytesAllocated](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#getTotalBytesAllocated())`()` Returns the total number of bytes currently allocated.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                 | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocation))`(allocation: `[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)`!)` Releases an[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)back to the allocator.                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                 | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocator.AllocationNode))`(allocationNode: `[Allocator.AllocationNode](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode)`!)` Releases all[Allocations](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)in the chain starting at the given[AllocationNode](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode). |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                 | [trim](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#trim())`()` Hints to the allocator that it should make a best effort to release any excess[Allocations](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).                                                                                                                                                                                                                                                                                                                       |

## Public functions

### allocate

```
fun allocate(): Allocation!
```

Obtain an[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).

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

|                                                    Returns                                                    |
|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| [Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)`!` | The[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation). |

### getIndividualAllocationLength

```
fun getIndividualAllocationLength(): Int
```

Returns the length of each individual[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).  

### getTotalBytesAllocated

```
fun getTotalBytesAllocated(): Int
```

Returns the total number of bytes currently allocated.  

### release

```
fun release(allocation: Allocation!): Unit
```

Releases an[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)back to the allocator.  

|                                                         Parameters                                                          |
|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| `allocation: `[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)`!` | The[Allocation](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)being released. |

### release

```
fun release(allocationNode: Allocator.AllocationNode!): Unit
```

Releases all[Allocations](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation)in the chain starting at the given[AllocationNode](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode).

Implementations must not make memory allocations.  

### trim

```
fun trim(): Unit
```

Hints to the allocator that it should make a best effort to release any excess[Allocations](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation).