This week's book giveaway is in the NodeJS forum. We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line! See this thread for details.
Tip: perform a dry run on this code. Draw the reference variables on the stack and the objects heap. When the reference variables are set to null, remove the link between the stack reference variable and the object on the heap. Pay special attention to the assignment on line 12! What's special about Alpha.b1? Once you are done, see how many objects are accessible through variables on the stack (in this case: a2 is the only non null varaible at the end).
Rather than tell you why, give the above a go and see if you get to the correct answer, I've given you a big hint ;)
a2 is not nulled out, so the new A instance it refers to is retained. It holds a reference to b2 through the member variable, so b2 is alive.
b1 is referred to in the static member of the class Alpha, so the only object ripe for Nirvana at this point is a1.
My, my, aren't you a big fella. Here, have a tiny ad:
global solutions you can do at home or in your backyard