SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
So, after the statement b=a the object refered by a is now refered by b.
So the object refered by a is not eligible for GC even you assign a to null because b is referring that.
But, here object referenced by b is eligible for GC because nothing is refer to this object now.
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Can someone clarify this.
SCJP 5
Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Are you agreeing with Venkata, that nothing is eligible for GC.
object referenced by b is eligible for GC because nothing is refer to this object now.
Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
But with Strings,
String s="null";
String s1="not null";
s1=s;
s=null;(here s is eligible for garbage collection, then the object s1 refering to s will not be eligible for garbage collection as it still refers to "null")
Best Regards,<br />Vipin<br />MCA, SCJP5, SCWCD in progress
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
String Objects are of two types.
One created on Heap and the Other created in String Constant pool.
Originally posted by bittoo garg:
String objects are always created on heap.
Objects are never created in String Constant Pool.
Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
The Strings Chapter in K&B book clearly explains this concept.
But I think discussion on String Constant Pool is beyond the scope of SCJP