A non-preventing (weak) reference to a service.

Unlike ServiceRef, this does not keep the service alive in memory. The garbage collector can collect the underlying object even while this ref exists. Use .deref() to check if the service is still available.

1.2.0

const weakRpc = strongRef.toWeak();

// In another component — check before use
const rpc = weakRpc.deref();
if (rpc) {
await rpc.getBalance(pubkey);
} else {
// Service was GC'd — re-acquire if needed
}

Type Parameters

  • T extends object

    The service type (must be an object).

Constructors

Accessors

Methods

Constructors

Accessors

  • get alive(): boolean
  • Whether the underlying object is still alive (not yet GC'd).

    Returns boolean

Methods

  • Dereference the weak ref.

    Returns undefined | T

    The service instance, or undefined if it was GC'd.