Memory Management: Memory Deallocation
new with previously allocated memory will be deallocated with
Circle* c= new Circle;
The destructors of the object and the destructors of all base classes will be automatically called. If the destructor of the base class is virtual, we can destroy the object with a pointer or reference to the base class.
After the memory of the object is deallocated, the access to the object is undefined. We must initialize the pointer of the object to a point it to a different object.
The deallocation of
newallocated object with
deletehas undefined behavior.