Function SharedPtr.useCount

Returns the number of different SharedPtr instances

ControlType.Shared useCount(This)() const nothrow @nogc @property scope @safe;

Returns the number of different SharedPtr instances (this included) managing the current object or 0 if there is no managed object.

Examples

SharedPtr!long x = null;

assert(x.useCount == 0);

x = SharedPtr!long.make(123);
assert(x.useCount == 1);

auto y = x;
assert(x.useCount == 2);

auto w1 = x.weak;    //weak ptr
assert(x.useCount == 2);

SharedPtr!long.WeakType w2 = x;   //weak ptr
assert(x.useCount == 2);

y = null;
assert(x.useCount == 1);

x = null;
assert(x.useCount == 0);
assert(w1.useCount == 0);