×
Namespaces

Variants
Actions

Delete

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: vin2ktalks (04 May 2007)
Last edited: hamishwillee (20 Jul 2012)

delete Operator

The delete operator destroys the object created with new by deallocating the memory associated with the object.

The operand of delete must be a pointer returned by new, and cannot be a pointer to constant. Deleting a null pointer has no effect.

The delete[] operator frees storage allocated for array objects created with new[]. The delete operator frees storage allocated for individual objects created with new.

The result of deleting an array object with delete is undefined, as is deleting an individual object with delete[]. The array dimensions do not need to be specified with delete[].

The result of any attempt to access a deleted object or array is undefined.

If a destructor has been defined for a class, delete invokes that destructor. Whether a destructor exists or not, delete frees the storage pointed to by calling the function operator delete() of the class if one exists.

The global ::operator delete() is used if:

* The class has no operator delete().
* The object is of a nonclass type.
* The object is deleted with the ::delete expression. 

The global ::operator delete[]() is used if:

* The class has no operator delete[]()
* The object is of a nonclass type
* The object is deleted with the ::delete[] expression. 

The default global operator delete() only frees storage allocated by the default global operator new(). The default global operator delete[]() only frees storage allocated for arrays by the default global operator new[]().

This page was last modified on 20 July 2012, at 09:17.
32 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×