pub struct PrivateCollector { /* private fields */ }Expand description
Private garbage collector to limit the lifetime of allocated memory chunks.
When the PrivateCollector is dropped, it performs an aggressive reclamation; it deallocates
all remaining memory chunks that it has collected in its lifetime without ensuring that there
are no active Ptr or RawPtr pointing to any of the memory
chunks.
§Safety
Using PrivateCollector for types that do not implement Send is unsafe, as their
instances may be dropped on an arbitrary thread. See collect_owned and
collect_shared for more safety notes.
Implementations§
Source§impl PrivateCollector
impl PrivateCollector
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new PrivateCollector.
§Examples
use sdd::PrivateCollector;
let private_collector = PrivateCollector::new();Sourcepub unsafe fn collect_owned<T>(&self, owned: Owned<T>, guard: &Guard)
pub unsafe fn collect_owned<T>(&self, owned: Owned<T>, guard: &Guard)
Collects the memory owned by the supplied Owned.
§Safety
This method is unsafe because it manually manages the lifetime of the underlying memory. The
caller must ensure that the PrivateCollector is not dropped while any
Ptr or RawPtr still point to the memory held by the
Owned.
Additionally, T must implement Send because its instances may be dropped on an
arbitrary thread: for example, when the PrivateCollector is moved across threads or
shared among multiple threads. The Send constraint is intentionally not enforced at
compile time to allow for more flexibility.
§Examples
use sdd::{Guard, Owned, PrivateCollector};
let private_collector = PrivateCollector::new();
let owned = Owned::new(10);
unsafe { private_collector.collect_owned(owned, &Guard::new()); }Collects the supplied Shared.
Returns true if the last reference was dropped and the memory was successfully collected.
§Safety
This method is unsafe because it manually manages the lifetime of the underlying memory. The
caller must ensure that the PrivateCollector is not dropped while any
Ptr or RawPtr still point to the memory held by the
Shared.
Additionally, T must implement Send because its instances may be dropped on an
arbitrary thread: for example, when the PrivateCollector is moved across threads or
shared among multiple threads. The Send constraint is intentionally not enforced at
compile time to allow for more flexibility.
§Examples
use sdd::{Guard, PrivateCollector, Shared};
let private_collector = PrivateCollector::new();
let shared = Shared::new(10);
let collected = unsafe { private_collector.collect_shared(shared, &Guard::new()) };
assert!(collected);