Skip to content

Commit f8ef01e

Browse files
committed
Merge pull request #112 from AndrejMitrovic/classalocators
Add deprecation notes about class allocators/deallocators.
2 parents 63b0fcf + b1d1f0e commit f8ef01e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

class.dd

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ assert(mydate); // check that class Date invariant holds
748748
runs at maximum speed.
749749

750750
<h3>$(LNAME2 allocators, Class Allocators)</h3>
751-
751+
$(B Note): Class allocators are deprecated in D2.
752752
$(GRAMMAR
753753
$(GNAME ClassAllocator):
754754
$(B new) $(GLINK2 declaration, Parameters) $(GLINK2 function, FunctionBody)
@@ -812,7 +812,18 @@ new(1,2) Foo(a); // calls new(Foo.sizeof,1,2)
812812
)
813813

814814
<h3>$(LNAME2 deallocators, Class Deallocators)</h3>
815-
815+
$(B Note): Class deallocators and the delete operator are deprecated in D2.
816+
Use the $(B clear) function to finalize an object by calling its destructor.
817+
The memory of the object is $(B not) immediately deallocated, instead the GC
818+
will collect the memory of the object at an undetermined point after finalization:
819+
820+
------
821+
class Foo { int x; this() { x = 1; } }
822+
Foo foo = new Foo;
823+
clear(foo);
824+
assert(foo.x == int.init); // object is still accessible
825+
------
826+
816827
$(GRAMMAR
817828
$(GNAME ClassDeallocator):
818829
$(B delete) $(GLINK2 declaration, Parameters) $(GLINK2 function, FunctionBody)

0 commit comments

Comments
 (0)