ropool
    Preparing search index...

    Class ObjectHandle<T>

    A handle representing an object acquired from an ObjectPool. This handle is the primary way to interact with a pooled object and release it back to the pool. It provides a safe wrapper around the underlying object and prevents issues like double-freeing.

    Type Parameters

    • T

      The type of objects managed by the pool. ObjectHandle

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Internal

      Creates an instance of ObjectHandle.

      Type Parameters

      • T

      Parameters

      • id: number

        The unique ID of the object within the pool.

      • obj: T

        The object instance this handle wraps.

      • objPool: ObjectPool<T>

        The pool instance this handle belongs to. This constructor is intended for internal use by ObjectPool. Users should acquire handles via ObjectPool#acquire.

      Returns ObjectHandle<T>

    Accessors

    • get data(): T

      Gets the underlying object instance managed by this handle. Use this getter to access and modify the pooled object's properties.

      Returns T

      The pooled object.

    Methods

    • Internal

      For pool internal use to reset state on acquire.

      Returns void

    • Implements the Symbol.dispose method for the 'using' keyword. This allows the handle to be used with the using declaration (available in environments supporting the Explicit Resource Management proposal, e.g., Node.js 20+). When a using declaration goes out of scope, this method is automatically called, ensuring the object is released back to the pool.

      Returns void

      using handle = pool.acquire();
      // Use handle.data
      // handle.free() is automatically called when exiting this block
    • Releases the object back to the pool, making it available for reuse. This method is idempotent; calling it multiple times on the same handle instance will only release the object once. After calling free(), the handle should no longer be used.

      Returns void

      const handle = pool.acquire();
      // Use handle.data
      handle.free(); // Release the object
      handle.free(); // Calling again does nothing