import std.experimental.allocator: theAllocator, make, makeArray;
static int x;
static interface I
{
void method();
}
static class A : I
{
int y;
override void method() { x = 21; }
~this() { x = 42; }
}
static class B : A
{
}
auto a = theAllocator.make!A;
a.method();
assert(x == 21);
theAllocator.dispose(a);
assert(x == 42);
B b = theAllocator.make!B;
b.method();
assert(x == 21);
theAllocator.dispose(b);
assert(x == 42);
I i = theAllocator.make!B;
i.method();
assert(x == 21);
theAllocator.dispose(i);
assert(x == 42);
int[] arr = theAllocator.makeArray!int(43);
theAllocator.dispose(arr);
Destroys and then deallocates (using alloc) the object pointed to by a pointer, the class object referred to by a class or interface reference, or an entire array. It is assumed the respective entities had been allocated with the same allocator.