Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Gabbage Collection

807605Aug 16 2007 — edited Aug 17 2007
Answer? Well, I think r2 is always referred to, likewise r3, r4 and r5. r1 seems inaccessible, but is still reffered to on line 10. So is the answer none or can r1 still be gabbage collected pls?

Thanx

Given:

1. class Rubbish {
2. public static void main(String [] args) {
3. Rubbish r1 = new Rubbish();
4. Rubbish r2 = new Rubbish();
5. Rubbish r3 = new Rubbish();
6. Rubbish r4 = r2;
7. Rubbish r5 = r4;
8. r2 = null;
9. r4 = r2;
10. r1 = r5;
11. // do stuff
12. }
13. }


At the point that line 12 is reached, how many objects are eligible for garbage collection?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2007
Added on Aug 16 2007
6 comments
162 views