Ok. Object 1 owns object 2. This is explicit. Object 3 has a reference to object 2 because it needs to work with some data it has. Object 1 dies, so it kills object 2 as well. This is also explicit.
The two statements marked in bold both represent potential problems with this design:
- Object 1's lifetime is non-deterministic by virtue of being garbage collected, so by tying object 2's lifetime to object 1, you have made object 2's lifetime non-deterministic as well.
- If object 3 stores a reference to object 2, then it has assumed co-ownership of object 2, and object 2 can no longer be solely tied to object 1's lifetime.
There are a couple of questions that are worthwhile to ask at this point:
- Why is the lifetime of object 2 tied to that of object 1, instead of being tied to program lifecycle events (i.e. level unload, application shutdown, etc)?
- Why does object 3 store a reference to object 2? Is the a concrete reason why it could not be passed that reference each time it needs access to the data?
- Why cannot object 3 maintain a reference to object 1 instead?