1 import std.experimental.allocator: theAllocator, make, makeArray;
2
3 static int x;
4 static interface I
5 {
6 void method();
7 }
8 static class A : I
9 {
10 int y;
11 override void method() { x = 21; }
12 ~this() { x = 42; }
13 }
14 static class B : A
15 {
16 }
17 auto a = theAllocator.make!A;
18 a.method();
19 assert(x == 21);
20 theAllocator.dispose(a);
21 assert(x == 42);
22
23 B b = theAllocator.make!B;
24 b.method();
25 assert(x == 21);
26 theAllocator.dispose(b);
27 assert(x == 42);
28
29 I i = theAllocator.make!B;
30 i.method();
31 assert(x == 21);
32 theAllocator.dispose(i);
33 assert(x == 42);
34
35 int[] arr = theAllocator.makeArray!int(43);
36 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.