dispose

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.

  1. void dispose(auto ref A alloc, T* p)
    void
    dispose
    (
    A
    T
    )
    (
    auto ref A alloc
    ,
    T* p
    )
  2. void dispose(auto ref A alloc, T p)
  3. void dispose(auto ref A alloc, T[] array)

Examples

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);
1 import std.experimental.allocator: make;
2 import std.experimental.allocator.mallocator : Mallocator;
3 
4 interface Foo {}
5 class Bar: Foo {}
6 
7 Bar bar;
8 Foo foo;
9 bar = Mallocator.instance.make!Bar;
10 foo = cast(Foo) bar;
11 Mallocator.instance.dispose(foo);

Meta