delete vs ::delete in c++


Most of the time you just write:

Base* ptr = new Derived();
delete ptr;           // virtual destructor cleans up Derived as expected

A delete-expression does two related jobs: it destroys the object and then selects a deallocation function to release its storage. With a virtual destructor, deleting through a base pointer still destroys the most-derived object.

If you add the global-scope qualifier:

::delete ptr;         // bypasses class-specific operator delete lookup

the destructor still runs and the whole allocation is still released. The qualifier changes where the deallocation function is found: it skips class-scope lookup and selects an appropriate global operator delete.

It does not free only sizeof(Base), and it does not leave the derived part behind. Sized and aligned deallocation overloads can affect which function is called, but a normal global deallocator releases the allocation as one block.

when would you ever want ::delete?

When you deliberately need to bypass a class-specific deallocation policy and know the storage can be returned through the global deallocator. That is specialized code. For everyday ownership, use plain delete.

One more distinction: calling ::operator delete(ptr) directly is not a delete-expression and does not run a destructor. ::delete ptr does.

quick checklist

expressionwhat happensusual role
delete ptr; destroys the object, then uses normal class/global lookup ordinary code
::delete ptr; destroys the object, then uses a global deallocator deliberate low-level use

Bottom line: use plain delete unless you have a concrete, allocator-level reason to do otherwise.

Reference: C++ draft, delete-expression.