Object Delete Operator delete

**Overview**

The delete operator is used to remove objects that were previously created using the new operator. It performs two primary actions: it invokes the destructor of the class associated with the object, and then it releases the memory that was occupied by that object.

**Syntax and Usage**

  • **Operand**: The operator requires a real descriptor of an existing object as its operand. This descriptor typically refers to an object created dynamically.
  • **Effect on Descriptor**: Immediately after the delete operation is successfully executed, the object descriptor that was used as the operand becomes invalid. Attempting to access the object through this descriptor afterwards will lead to undefined behavior.
  • **Example**

    //--- delete figure
    delete m_shape;
    m_shape = NULL; // Recommended practice to nullify descriptor
    //--- create a new figure
    NewShape();
    

    **Related Concepts**

  • **Object Creation**: new operator
  • **Object Lifetime**: Creating and Deleting Objects
  • **Memory Management**: Initialization of Variables, Visibility Scope and Lifetime of Variables
  • **Object Pointers**: Object Descriptors