|
69 | 69 | $(LI $(RELATIVE_LINK2 invariants, Class Invariants))
|
70 | 70 | $(LI $(DDSUBLINK spec/unittest, unittest, Unit Tests))
|
71 | 71 | $(LI $(RELATIVE_LINK2 allocators, Class Allocators))
|
72 |
| - $(LI $(RELATIVE_LINK2 deallocators, Class Deallocators)) |
73 | 72 | $(LI $(RELATIVE_LINK2 alias-this, Alias This))
|
74 | 73 | )
|
75 | 74 | )
|
@@ -1070,60 +1069,6 @@ new(1,2) Foo(a); // calls new(Foo.sizeof,1,2)
|
1070 | 1069 | Explicit Class Instance Allocation).
|
1071 | 1070 | )
|
1072 | 1071 |
|
1073 |
| -$(H2 $(LNAME2 deallocators, Class Deallocators)) |
1074 |
| -$(B Note): Class deallocators and the delete operator are deprecated in D2. |
1075 |
| -Use the $(D destroy) function to finalize an object by calling its destructor. |
1076 |
| -The memory of the object is $(B not) immediately deallocated, instead the GC |
1077 |
| -will collect the memory of the object at an undetermined point after finalization: |
1078 |
| - |
1079 |
| ------- |
1080 |
| -class Foo { int x; this() { x = 1; } } |
1081 |
| -Foo foo = new Foo; |
1082 |
| -destroy(foo); |
1083 |
| -assert(foo.x == int.init); // object is still accessible |
1084 |
| ------- |
1085 |
| - |
1086 |
| -$(GRAMMAR |
1087 |
| -$(GNAME Deallocator): |
1088 |
| - $(D delete) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionBody) |
1089 |
| -) |
1090 |
| - |
1091 |
| -$(P A class member function of the form:) |
1092 |
| - |
1093 |
| ------- |
1094 |
| -delete(void *p) |
1095 |
| -{ |
1096 |
| - ... |
1097 |
| -} |
1098 |
| ------- |
1099 |
| - |
1100 |
| - is called a class deallocator. |
1101 |
| - The deallocator must have exactly one parameter of type $(D void*). |
1102 |
| - Only one can be specified for a class. |
1103 |
| - When a delete expression: |
1104 |
| - |
1105 |
| ------- |
1106 |
| -delete f; |
1107 |
| ------- |
1108 |
| - |
1109 |
| -is executed, and f is a reference to a class instance that has a deallocator, |
1110 |
| -the deallocator is called with a pointer to the class instance after the |
1111 |
| -destructor (if any) for the class is called. It is the responsibility of the |
1112 |
| -deallocator to free the memory. |
1113 |
| - |
1114 |
| - $(P Derived classes inherit any deallocator from their base class, |
1115 |
| - if one is not specified. |
1116 |
| - ) |
1117 |
| - |
1118 |
| - $(P The class allocator is not called if the instance is created |
1119 |
| - on the stack. |
1120 |
| - ) |
1121 |
| - |
1122 |
| - $(P See also |
1123 |
| - $(LINK2 https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation, |
1124 |
| - Explicit Class Instance Allocation). |
1125 |
| - ) |
1126 |
| - |
1127 | 1072 | $(H2 $(LEGACY_LNAME2 AliasThis, alias-this, Alias This))
|
1128 | 1073 |
|
1129 | 1074 | $(GRAMMAR
|
|
0 commit comments