Struct RefCounted

A struct to ensure only one copy of the provided item exists.

struct RefCounted(T) ;

This differs from Phobos' std.typecons.RefCounted by using the GC to store the memory, instead of C's heap. The benefit here is that this version of RefCounted can be @safe.

The block containing the item is pinned in the GC until all references are gone, which means the destructor will be run synchronously when the last reference is removed. Therefore, it is safe to store a RefCounted struct inside a GC allocated type.

Constructors

NameDescription
this (args) Constructor. the underlying T is constructed using the parameters.

Methods

NameDescription
_get () Get a reference to the item. Note that if you store a reference to this item, it is possible the item will in the future be destroyed, but the memory will still be present (until the GC cleans it up).
opAssign (other) Assignment to another T.
opAssign (other) Assignment to another ref counted item.