devxlogo

How Do ‘New’ and ‘Delete’ Actually Work?

The C++ runtime library includes a heap manager (subroutines responsible for maintaining the heap). The heap manager does bookkeeping to keep track of which parts of the heap have been loaned out for usage (allocated), and which parts are still free (deallocated).

Every time a call to ‘new’ is made, the heap manager does the following things:

(1) It searches the free part of the heap for a chunk of memory that is big enough.

(2) It makes a record of the fact that the chunk of memory is now allocated.

(3) It returns the starting address of the allocated chunk as a result.

When you call delete, the heap manager updates its records to note that the block is free.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.