pub struct FinalizableHandle { /* private fields */ }Expand description
FinalizableHandle can be used as payload in super::Value::FinalizableHandle.
Will be received in Dart as instance of FinalizableHandle. When the Dart
instance gets garbage collected, the finalizer closure specified in
`FinalizableHandle::new will be invoked.
FinalizableHandle must be created on main thread, but other methods are thread safe.
Implementations§
Source§impl FinalizableHandle
impl FinalizableHandle
Sourcepub fn new<F: FnOnce() + 'static>(
external_size: isize,
isolate_id: IsolateId,
finalizer: F,
) -> Self
pub fn new<F: FnOnce() + 'static>( external_size: isize, isolate_id: IsolateId, finalizer: F, ) -> Self
Creates a new finalizable handle instance. Must be created on main thread and the finalizer will also be invoked on main thread.
If FinalizableHandle gets dropped the finalizer will not be executed. The finalizer is guaranteed to be executed even if the target isolate gets destroyed before it had chance to create dart weak persistent handle.
§Arguments
-
finalizer- closure that will be executed on main thread when the Dart object associated with this handle is garbage collected. The closure will not be invoked when thisFinalizableHandleis dropped. -
external_size- hit to garbage collector about how much memory is taken by native object. Used when determining memory pressure.
Sourcepub fn is_attached(&self) -> bool
pub fn is_attached(&self) -> bool
Whether this handle is attached to a Dart object. This will be false
initially and becomes true once the Finalizable handle is send to Dart.
false after the Dart counterpart gets garbage collected.
Sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Whether the Dart object was already garbage collected finalized.
Sourcepub fn update_size(&self, size: isize)
pub fn update_size(&self, size: isize)
Updates the external size. This is a hint to Dart garbage collector.