Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions spec/class.dd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ $(UL
$(LI $(RELATIVE_LINK2 invariants, Class Invariants))
$(LI $(DDSUBLINK spec/unittest, unittest, Unit Tests))
$(LI $(RELATIVE_LINK2 allocators, Class Allocators))
$(LI $(RELATIVE_LINK2 deallocators, Class Deallocators))
$(LI $(RELATIVE_LINK2 alias-this, Alias This))
)
)
Expand Down Expand Up @@ -1070,60 +1069,6 @@ new(1,2) Foo(a); // calls new(Foo.sizeof,1,2)
Explicit Class Instance Allocation).
)

$(H2 $(LNAME2 deallocators, Class Deallocators))
$(B Note): Class deallocators and the delete operator are deprecated in D2.
Use the $(D destroy) function to finalize an object by calling its destructor.
The memory of the object is $(B not) immediately deallocated, instead the GC
will collect the memory of the object at an undetermined point after finalization:

------
class Foo { int x; this() { x = 1; } }
Foo foo = new Foo;
destroy(foo);
assert(foo.x == int.init); // object is still accessible
------

$(GRAMMAR
$(GNAME Deallocator):
$(D delete) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionBody)
)

$(P A class member function of the form:)

------
delete(void *p)
{
...
}
------

is called a class deallocator.
The deallocator must have exactly one parameter of type $(D void*).
Only one can be specified for a class.
When a delete expression:

------
delete f;
------

is executed, and f is a reference to a class instance that has a deallocator,
the deallocator is called with a pointer to the class instance after the
destructor (if any) for the class is called. It is the responsibility of the
deallocator to free the memory.

$(P Derived classes inherit any deallocator from their base class,
if one is not specified.
)

$(P The class allocator is not called if the instance is created
on the stack.
)

$(P See also
$(LINK2 https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation,
Explicit Class Instance Allocation).
)

$(H2 $(LEGACY_LNAME2 AliasThis, alias-this, Alias This))

$(GRAMMAR
Expand Down