The old solution uses retain counts: Every object has a retain count, which should represent the number of other objects that have pointers to it. If the color is the favorite of two people, the retain count of that color should be 2. When it goes to zero, the object is deallocated.
The new solution, introduced in 10.5, is a garbage collector, which babysits the entire object graph, looking for objects that can't be reached from the variables that are in scope. The unreachable objects are automatically deallocated.