Chapter 4. Memory Management
Let’s say that there are two instances of
Person and that each has a
favoriteColor, a pointer to a color object. If two people have the same
favoriteColor, the objects will have pointers to the same color object. As the people age, their favorite color might change. Eventually, the color object might be no one’s favorite (Figure 4.1).
Figure 4.1. The Problem
We do not want this orphaned color to be taking up room in our program’s memory. We want the memory deallocated, so that we can put new objects in that memory, but we must be sure that the color is not deallocated while any objects are pointing to it.
This is a relatively ...