
352 ◾ Appendix B
B.2 OWNERSHIP
C++ programmers must track and deallocate heap memory. When should
a programmer deallocate? Match every new to a delete is a simplistic man-
tra that is dicult to follow in the midst of function calls and aliases. We
provide examples next of pointer usage with respect to memory owner-
ship. e rst function in Example B3 calls the new operator to allocate
a single integer on the heap. When this function executes at runtime, the
address of the heap integer so allocated is returned (and assigned to the
local pointer variable heapInt). In the unlikely event that there is insu-
cient memory available to allocate ...