At source code line 3, s1 refers to a String object. At line 4, s1 is set to null. Normally we would say the object is eligible for gc after line 4.
But byte code line 5 is loading the same reference as byte code line 0. ldc is the byte code instruction to load a reference to an instance of class String representing a String literal. #2 is an index into the runtime constant pool (not String pool). This is as close as I can come to proving that interned String objects are not garbage collected. [ November 08, 2003: Message edited by: Marlene Miller ]
Joined: Aug 24, 2003
Thanks Marlene. GC combined with string literals can get tricky.
The good news is that "for the purpose of the exam" (sorry Marlene, it's the focus police again ), GC and the String pool won't be mixed together. When the exam asks you to determine how many objects are eligible for the GC, it won't be referring to String objects.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com