__delete

fnvoid __delete(T)(ref T x) @system

Destroys and then deallocates an object.

In detail, __delete(x) returns with no effect if x is null. Otherwise, it performs the following actions in sequence:

  • Calls the destructor ~this() for the object referred to by x

    (if x is a class or interface reference) or for the object pointed to by x (if x is a pointer to a struct). Arrays of structs call the destructor, if defined, for each element in the array. If no destructor is defined, this step has no effect.

  • Frees the memory allocated for x. If x is a reference to a class

    or interface, the memory allocated for the underlying instance is freed. If x is a pointer, the memory allocated for the pointed-to object is freed. If x is a built-in array, the memory allocated for the array is freed. If x does not refer to memory previously allocated with new (or the lower-level equivalents in the GC API), the behavior is undefined.

  • Lastly, x is set to null. Any attempt to read or write the freed memory via

    other references will result in undefined behavior.

Note

Users should prefer destroy, object to explicitly finalize objects,

and only resort to __delete when destroy, object wouldn't be a feasible option.

Parameters

xaggregate object that should be destroyed

See Also

destroy, object, GC.free

History

The delete keyword allowed to free GC-allocated memory.

As this is inherently not @safe, it has been deprecated. This function has been added to provide an easy transition from delete. It performs the same functionality as the former delete keyword.