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.
Can someone clarify this.
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.
But with Strings,
String s1="not null";
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")
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.
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
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton