Struct tracing_rc::rc::Gc [−][src]
pub struct Gc<T: Traceable + 'static> { /* fields omitted */ }
Expand description
A cycle-collected reference-counted smart pointer.
Gc<T>
provides shared ownership of a value of type T
, allocated on the heap. Cloining it
will produce a new Gc
instance which pints to the same allocation as the original Gc
.
Unlike std::rc::Rc
, Gc
pointers may refer to each other in a way that creates cycles
arbitrarily without causing leaks, provided that the program calls collect
to collect those
cycles.
It’s important to note a few things about collection:
- The default
collect
implementation only performs cycle-tracing collection if a node has been in waiting for collection for a while. This is so that we don’t pay the cost of tracing for acyclic nodes which may be marked for collection due to the number of outstanding references, but don’t actually participate in a cycle. You may usecollect_full
to force tracing collection of all pending nodes if you prefer. - Dropping of data is deferred until a call to
collect
orcollect_full
is made, and the collector is able to determine that theGc
is actually dead. The collector guarantees that (in the absence of bugs) theDrop
implementation for your type will be executed if it is determined to be dead, but cannot provide any guarantees on when it will be executed.collect
has weak guarantees even in the presence of acyclic pointers - if a node containing your type is acyclic, but has N strong references, it may take up tomin(N,
[CollectionOptions::old_gen_threshold
]+ 1)
calls tocollect
for the value to be cleaned up even if all parents are dropped.- The collector does guarantee that if
collect_full
is used, theDrop
implementation for your data will have been executed by the timecollect_full
completes if the value is dead.
- The collector does not make any guarantees about the relative order of drops for dead nodes. Even if the order appears stable, you may not rely on it for program correctness.
Implementations
Retrieve the current number of strong references outstanding.
Returns true if the data in Self hasn’t been dropped yet. This will almost always be the case unless it is called inside of a Drop implementation or if there is a bug present in a Traceable impl.
Get a reference into this Gc.
Returns None if the pointer is dead, as the data contained in this pointer is possibly cleaned up.
Try to get a mutable referenced into this Gc. Will return None if there are oustanding strong references to this, or if the pointer is dead.
Gets a reference into this Gc without checking if pointer is still alive.
Safety
This gc pointer must not have had its inner data dropped yet
Gets a reference into this Gc without checking if pointer is still alive or has unique access
Safety
- This gc pointer must not have had its inner data dropped yet.
- There must be no other aliasing references to the inner data.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Visit the gc pointers owned by this type. Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for Gc<T>
impl<T> !UnwindSafe for Gc<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.