Lens Scripting API
    Preparing search index...

    A generic object pool for recycling objects to reduce pressure on the garbage collector.

    Type Parameters

    • T
    Index

    Constructors

    Accessors

    • get available(): number

      The number of objects currently available in the pool.

      Returns number

    • get capacity(): number

      The total number of objects managed by this pool (both available and in use).

      Returns number

    • get inUse(): number

      The number of objects that are currently "checked out" of the pool.

      Returns number

    Methods

    • Allows the pool to be used in for...of loops, iterating over available items.

      Returns Iterator<T>

    • Executes a callback for each available item in the pool.

      Parameters

      • callback: (item: T, index: number, array: T[]) => void

        The function to execute for each item.

      Returns void

    • Returns an object with the current pool statistics.

      Returns PoolStats

      An object containing capacity, available, inUse, and utilizationRate.

    • Retrieves an object from the pool. If the pool is empty, it will automatically grow to create new objects.

      Returns T

      An object of type T.

    • Explicitly adds a specified number of new objects to the pool.

      Parameters

      • amount: number

        The number of new objects to create.

      Returns void

    • Returns an object to the pool, making it available for reuse.

      Parameters

      • item: T

        The object to return to the pool.

      Returns void

    • Forcibly returns all borrowed items to the pool.

      This is a powerful tool for preventing memory leaks. By calling this at the beginning of a frame or a top-level operation, you ensure that any objects that were not explicitly released are reclaimed.

      Returns void