posted 24 years ago
HI,
I believe the answer is technically: 4 are available for garbage collection. Why?
1. str = "0" inside loop
2. str = "1" inside loop
3. str = "2" inside loop
4. str = "3" inside loop
5. str = "4" inside loop
Since str still points to "4" that is not eligible for garbage collection. That would not be the case if str was local variable but it is an instance variable in this case.
Therefore from the line numbers above we can see that there are 4 String objects ready for garbage collection:
"0",
"1",
"2", and
"3".
Regards,
Manfred.
[This message has been edited by Manfred Leonhardt (edited February 16, 2001).]