Library API
    Preparing search index...

    Class Finalizer<T>

    Wrapper around FinalizationRegistry providing typed, safe resource cleanup callbacks triggered when objects are reclaimed by the Garbage Collector.

    Type Parameters

    • T = void
    Index
    • Type Parameters

      • T = void

      Parameters

      • callback: (heldValue: T) => void

      Returns Finalizer<T>

    • get isFinalizer(): boolean

      Returns true to identify this instance as a Finalizer.

      Returns boolean

    • Registers a target object with a held value and optional unregister token.

      Parameters

      • target: WeakKey

        The object to observe for garbage collection

      • heldValue: T

        The value passed to the cleanup callback

      • OptionalunregisterToken: WeakKey

        Optional token to unregister the callback prior to GC

      Returns void

    • Unregisters a previously registered finalizer callback.

      Parameters

      • unregisterToken: WeakKey

        The token used during registration

      Returns boolean

      True if a registration was found and removed

    • Registers an object to execute a cleanup callback when garbage collected. Returns a function to cancel the finalizer registration prior to GC.

      Parameters

      • target: WeakKey

        The target object to observe for garbage collection

      • cleanup: () => void

        The teardown callback to execute upon GC reclamation

      • OptionalunregisterToken: WeakKey

        Optional token used for unregistration (defaults to a unique token object)

      Returns () => boolean

      A teardown function that cancels the finalization registration without retaining target