Skip to main content

make_garbage_collected

Function make_garbage_collected 

Source
pub unsafe fn make_garbage_collected<T: GarbageCollected + 'static>(
    heap: &Heap,
    obj: T,
) -> UnsafePtr<T>
Expand description

Constructs an instance of T, which is a garbage collected type.

The object will be allocated on the heap and managed by cppgc. During marking, the object will be traced by calling the trace method on it.

During sweeping, the destructor will be called and the memory will be freed.

ยงSafety

The caller must ensure that the returned pointer is always stored on the stack, or is safely moved into one of the other cppgc pointer types.