my.gc.refc

Source.

Reference counting using the GC.

The RefCounted struct simply stores the item in a GC block, and also adds a root to that block. Once all known references to the block are removed (tracked by a reference count in the block), then the block is removed, and the destructor run. Since it's a root, it can run the full destructor of the data underneath, without worrying about GC data being collected underneath it.

This depends on the block not being involved in a cycle, which should be fine for iopipes.

Note that atomics are used for the reference count because the GC can destroy things in other threads.

Members

Functions

refCounted
RefCounted!T refCounted(T item)
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

RefCounted
struct RefCounted(T)

RefCounted is a smart pointer that retains shared ownership of an object through a pointer. Several RefCounted objects may own the same object. The object is destroyed and its memory deallocated when either of the following happens:

WeakRef
struct WeakRef(T)

WeakRef is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by RefCounted. It must be converted to a RefCounted via asRefCounted() in order to access the referenced object.

Meta