Search⌘ K

Release of Memory

Explore how to correctly release memory in C++ by using the delete operator for single objects and delete[] for arrays. Understand the importance of virtual destructors in class hierarchies and avoid undefined behaviors by matching allocation and deallocation methods.

We'll cover the following...

delete #

The delete operator deallocates the memory allocated by the new operator.

Point* p = new Point(1.0, 2.0);
delete p;

If the deleted object belongs to a type hierarchy, the ...