Garbage collection
1 posts in topic
Flat View  Flat View

Posted By:   Abhay_Shukla
Posted On:   Wednesday, December 29, 2004 10:55 AM

Line 1: methodA() {

Line 2: return new String("name");

Line 3:}

Line 4:someMeth() {

Line 5:String s = "aaa";

Line 6:s = methodA();

Line 7:s = null;

Line 8:}

could anyone tell is I am correct in saying that object s is eligible for garbage collection after execution of line 6

Re: Garbage collection

Posted By:   Chandra_Patni  
Posted On:   Wednesday, December 29, 2004 12:41 PM

String object "aaa" is eligible for GC. However, if string "aaa" already interned (due to a completely unrelated side effect), then s will be pointing to the already interned "aaa" object. So, line 5 will not have created a new string object. This is no loss no gain scenario.
About | Sitemap | Contact