scjp6 processing.....
SCJP 1.6 96%
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Neha Daga Wrote
you must see that b1 in Alpha class is static that is it doesn't belong to any object of class.
reffered by static b1 of class Alpha and has will not be eligible to gc as static b1 is a live reference.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
In the code a1 will be null so it will be eligible for garbage collection , b1 and b2 are also assigned null but the actual object being referenced by both of them is still having live references. b2 is still having reference from a2.b2 and b1 is still having live reference from a2.b1 ( because b1 is a static member and will be common to all the instances.
Rajesh Shinde wrote:In book it says B.
scjp6 processing.....
Rajesh Shinde wrote:So as i understand since Alpha.b1 is a static variable, so object referenced by it, will not be available for gc, but if we make a2=null, then object referred by static variable b1 might be available for gc as "An object is eligible for GC if it is not reachable by a live thread. It does not matter if the reference to the object is static."
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
scjp6 processing.....
Are we home yet? Wait, did we forget the tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|