Pool

sealed interface Pool<E : Any>

An object pool for reusing mutable objects to reduce garbage collection overhead.

Parameters

E

Type of objects to be pooled

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun borrow(): E

Borrow an object from the pool. If pool is empty, a new object is created.

Link copied to clipboard
abstract fun borrowInto(destination: MutableCollection<E>, count: Int)

Borrow count objects and add them into destination. The order of addition is not permitted.

Link copied to clipboard
abstract fun clear(): Int

Clear all stored objects.

Link copied to clipboard
abstract fun clearInto(destination: MutableCollection<E>): Int

Clear all stored objects and add them into destination. The order of addition is not permitted.

Link copied to clipboard
abstract fun recycle(value: E)

Recycle an object back to the pool for future reuse.

Link copied to clipboard
abstract fun recycleAll(values: Iterable<E>)

Recycle multiple objects at once.

Link copied to clipboard
open fun synchronized(): Pool<E>

Returns a thread-safe synchronized version of this pool.

Link copied to clipboard
inline fun <E : Any, R> Pool<E>.use(action: (E) -> R): R

Scoped use of a pooled object. Automatically recycles the object after use.