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.
Since
1.2.0
Example
constweakRpc = strongRef.toWeak();
// In another component — check before use constrpc = weakRpc.deref(); if (rpc) { awaitrpc.getBalance(pubkey); } else { // Service was GC'd — re-acquire if needed }
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.Since
1.2.0
Example