Function bindWeak

  • Starts monitoring the lifetime of target. Calls callback as soon as value has been garbage-collected, or the script is about to get unloaded.

    Useful when you're building a language-binding where you need to free native resources when a JS value is no longer needed.

    Be careful so callback is not a closure that accidentally captures target and keeps it alive beyond its intended lifetime.

    Parameters

    • target: any

      Heap-allocated JavaScript value to monitor lifetime of.

    • callback: WeakRefCallback

      Function to call when target gets GCed.

    Returns WeakRefId

Generated using TypeDoc