hosanna-ui-docs - v0.9.0
    Preparing search index...

    InstancePool manages reusable object instances for performance and memory efficiency. Implements the IInstancePool interface.

    Implements

    Index

    Constructors

    Properties

    clazzMap: Record<string, new () => IReusable> = {}

    Maps class names to their constructors for instantiation.

    pool: Record<string, IReusable[]> = {}

    The pool of reusable instances, keyed by class name.

    usedInstances: Record<string, number> = {}

    Tracks the number of used instances for each class.

    Methods

    • Retrieves an instance of the specified class from the pool or creates a new one if none are available.

      Type Parameters

      • T extends IReusable

        The type of the reusable instance.

      Parameters

      • className: string

        The name of the class to retrieve an instance for.

      • Optionalclazz: new () => T

        The constructor of the class to instantiate if no instances are available in the pool.

      Returns T

      An instance of the specified class.

    • Prepopulates the pool with a specified number of items.

      Type Parameters

      Parameters

      • className: string

        The class name to use as the key in the pool.

      • clazz: new () => T

        The class constructor to create new instances.

      • count: number

        The number of items to create and add to the pool.

      Returns void

    • Releases an item back into the pool for reuse.

      Type Parameters

      • T extends IReusable

        The type of the item that extends IReusable.

      Parameters

      • item: T

        The item to be released back into the pool.

      Returns void

      If the pool for the item's class does not exist, it will be created. If the item has an onWillRelease method, it will be called before the item is added back to the pool.