C++ does not have automatic garbage collection like Java does, so the programmer is generally responsible for ensuring objects that are created are subsequently destroyed. Any object that is created but not destroyed can cause a memory leak. The tradeoff for this manual memory management is the potential for improved application performance.

Scope in C++ makes this easier. For example, two objects created in block scope will be automatically deleted when execution moves out of the block scope. This programming idiom is referred to as scope-based resource management, which is a specific type of the resource acquisition is initialization (RAII) programming idiom. In RAII, resource allocation is done during object creation by the constructor and resource deallocation is done during object destruction by the destructor.

Referring back to the above example, if one of these objects is a pointer, then the pointer could be deleted while the object it is pointing to is not be deleted. If the existing pointer is the only valid reference to the object it points to, then the object it points to should be deleted to prevent a memory leak. Smart pointers in C++ make it easier to determine if there are other references to an object that a pointer points to and to automatically cleanup that object when no references remain.