The easiest way I have found is to go through the code line by line and every time a new object is created, draw a circle on a piece of paper, write the reference variable down, and draw a line between the two. Then, when that reference gets changed, mark out the first line and draw a line to the other object (or nothing, if null). Once you get through all of the code, count how many objects don't have any more live references and tada!*
Note: You could also get an island of isolation (I think that's the term I've seen...) where some object point to each other through instance variables, but don't have any live references in the program. Even though each object technically has a reference, since there is no way to access the objects anymore, they are eligible.
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Yes, three objects are eligible for GC,:-the object pointed to originally by gb1.g.g no
longer has a reference and also the objects pointed to originally by gb2.g and gb2.g.g also lose
any references pointing to them. I tend to use the same method as W. Joe Smith, although this was
a particularly nasty GC question. It seems to test your ability to solve puzzles rather than your
ability to program or your knowledge of Java.