- Why is it important to clearly express memory ownership in a program?
Clear memory ownership, and by extension, resource ownership, is one of the key attributes of a good design. With clear ownership, resources are certain to be created and made available in time for when they are needed, maintained while they are in use, and released/cleaned up when no longer needed.
- What are the common problems arising from unclear memory ownership?
The most common problems are resource leaks, including memory leaks; dangling handles (resource handles, such as pointers, references, or iterators, pointing to resources that do not exist); multiple attempts to release the same resource; and multiple attempts to construct the same resource.
- What types of memory ownership can be expressed in C++?
Non-ownership, exclusive ownership, shared ownership, as well as conversion between different...