Struct FinalizationRegistry
#[repr(transparent)]
pub struct FinalizationRegistry { /* private fields */ }
The FinalizationRegistry object lets you request a callback when an
object is garbage-collected.
FinalizationRegistry provides a way to request that a cleanup
callback get called at some point when an object registered with the
registry has been reclaimed (garbage-collected). Cleanup callbacks
are sometimes called finalizers.
Avoid where possible: cleanup callbacks should not be relied upon for anything essential. They are best used to reduce memory usage over the course of a program for objects that benefit from cleanup. Whether, when, and in what order callbacks fire is implementation-defined.
Implementations
impl FinalizationRegistry
fn register(&self, target: &JsValue, held_value: &JsValue)Registers
targetwith thisFinalizationRegistry. Whentargetis reclaimed by the garbage collector the cleanup callback may be called withheld_value.targetmust be an object (or a non-registered symbol).
impl FinalizationRegistry
fn register_with_token(&self, target: &JsValue, held_value: &JsValue, unregister_token: &JsValue)Registers
targetwith thisFinalizationRegistry, with anunregister_tokenthat can later be passed toFinalizationRegistry::unregisterto remove the registration.targetandunregister_tokenmust be objects (or non-registered symbols), and the same value may be passed for both.
impl FinalizationRegistry
fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistryCreates a new
FinalizationRegistrywith the given cleanup callback.The cleanup callback is invoked, at some point after a registered target is garbage-collected, with the
held_valuethat was passed toFinalizationRegistry::register. Because callbacks may be deferred or skipped entirely, the callback should normally outlive theFinalizationRegistry(for example by being created viaFunction::from_closure).
impl FinalizationRegistry
fn unregister(&self, unregister_token: &JsValue) -> boolUnregisters all entries registered with this
FinalizationRegistryusingunregister_token. Returnstrueif any cells were removed.
Trait Implementations
impl AsRef<FinalizationRegistry> for FinalizationRegistry
fn as_ref(&self) -> &FinalizationRegistry
impl AsRef<JsValue> for FinalizationRegistry
fn as_ref(&self) -> &JsValue
impl AsRef<Object> for FinalizationRegistry
fn as_ref(&self) -> &Object
impl Clone for FinalizationRegistry
fn clone(&self) -> Self
impl Debug for FinalizationRegistry
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Deref for FinalizationRegistry
type Target = Object;fn deref(&self) -> &Object
impl Eq for FinalizationRegistry
impl ErasableGeneric for FinalizationRegistry
type Repr = JsValue;
impl From<JsValue> for FinalizationRegistry
fn from(obj: JsValue) -> Self
impl FromWasmAbi for FinalizationRegistry
type Abi = <JsValue as FromWasmAbi>::Abi;unsafe fn from_abi(js: Self::Abi) -> Self
impl IntoJsGeneric for FinalizationRegistry
where
FinalizationRegistry: JsGeneric,
type JsCanon = FinalizationRegistry;fn to_js(self) -> FinalizationRegistry
impl IntoWasmAbi for FinalizationRegistry
type Abi = <JsValue as IntoWasmAbi>::Abi;fn into_abi(self) -> Self::Abi
impl JsCast for FinalizationRegistry
fn instanceof(val: &JsValue) -> boolfn unchecked_from_js(val: JsValue) -> Selffn unchecked_from_js_ref(val: &JsValue) -> &Self
impl LongRefFromWasmAbi for FinalizationRegistry
type Abi = <JsValue as LongRefFromWasmAbi>::Abi;type Anchor = FinalizationRegistry;unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
impl OptionFromWasmAbi for FinalizationRegistry
fn is_none(abi: &Self::Abi) -> bool
impl OptionIntoWasmAbi for FinalizationRegistry
fn none() -> Self::Abi
impl PartialEq for FinalizationRegistry
fn eq(&self, other: &Self) -> bool
impl Promising for FinalizationRegistry
type Resolution = FinalizationRegistry;
impl RefFromWasmAbi for FinalizationRegistry
type Abi = <JsValue as RefFromWasmAbi>::Abi;type Anchor = ManuallyDrop<FinalizationRegistry>;unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
impl StructuralPartialEq for FinalizationRegistry
impl UpcastFrom<FinalizationRegistry> for FinalizationRegistry
impl WasmDescribe for FinalizationRegistry
fn describe()