Function IntrusivePtr.useCount
Returns the number of different IntrusivePtr
instances
ControlType .Shared useCount(This)() const nothrow @nogc @property scope @safe;
Returns the number of different IntrusivePtr
instances (this
included) managing the current object or 0
if there is no managed object.
Examples
static struct Foo{
ControlBlock!(int, int) c;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
IntrusivePtr!Foo x = null;
assert(x .useCount == 0);
x = IntrusivePtr!Foo .make(123);
assert(x .useCount == 1);
auto y = x;
assert(x .useCount == 2);
auto w1 = x .weak; //weak ptr
assert(x .useCount == 2);
IntrusivePtr!Foo .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);