This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I found this question at MindQ 36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A? String name; String newName = "Nick"; newName = "Jason"; name = "Frieda"; String newestName = name; name = null; //Line A any comments/answers???. --Farooq
Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
My comment is that questions about GC should NEVER use String as an example due to the complication introduced by the String constant pool. In this code no new String objects have been created so there are none that are eligible. "Nick" etc are all constants created when the class loaded. Bill ------------------ author of:
I also think two objects are eligible for GC. Pls. correct if wrong ..
How many objects are eligible for gc after the last line?? String a = new String ("Hello"); String b = new String ("World"); String c = a + b; // c contains "HelloWorld" a = null; // as a has no more reference, eligible for GC b = c; // b contains "HelloWorld" c = null; // c has no reference, but b still contains "HelloWorld" b = c; // b now contains null reference , so it is eligible for GC