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.
Sebanti Sanyal wrote:I believe only one object created at line 8, Alpha alpha1 = new Alpha(); will be eligible for GC after line 18 but before main() returns.
Hi, I thought 2 objects would be eligible for GC, objects referenced by 'alpha1' and 'beta1'.
But your explanation also makes sence, since 'alpha1.b2' is a static reference, it means class 'Alpha' still can get to object referenced by 'beta1'.
But I'm still in doubt... Carlos, do you happen to have the answer for that question? so that we would know for sure...
Only one object reffered by alpha1 will be eligible for GC.
Object reffered by beta1 can be reached by Alpha.b1 (static reference lives in stack)
Object reffered by beta2 can be reached through b2 in alpha2.
Object reffered by alpha2 is reachable with no big trick.
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
global solutions you can do in your home or backyard