Hello,
I have modified the question and was wondering if 'obj' is eligible for GC right after line 4? objArray[1] still points to obj, so I'm not sure. obj is now null, but still has a reference pointing to it and is therefore not eligible for GC. Am I correct?
Object obj = new String("a");
Object objArray [] = new Object[2];
objArray[1] = obj;
obj = null; //line 4
About Question enthuware.ocajp.i.v8.2.883 :
Moderator: admin
-
- Posts: 24
- Joined: Wed Sep 02, 2015 3:43 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.883 :
Yes, you are correct. Even after line 4, objArray[1] is still pointing to the object pointed to by obj.
-
- Posts: 7
- Joined: Wed Nov 11, 2015 11:59 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.883 :
What if, instead of
objArr[0] = null;
at line 5, we had
objArr = null;
From what I understand, objArr would be eligible for GC. But not the String "aaaa" which is created at line 1. But when objArr gets GCd, the String "aaaa" will be eligible for GC. Or does the Garbage Collector have some special algorithm which enables it to detect such cases?(so that it can collect both objects at the same time)
objArr[0] = null;
at line 5, we had
objArr = null;
From what I understand, objArr would be eligible for GC. But not the String "aaaa" which is created at line 1. But when objArr gets GCd, the String "aaaa" will be eligible for GC. Or does the Garbage Collector have some special algorithm which enables it to detect such cases?(so that it can collect both objects at the same time)
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.883 :
You may want to read about "island of isolation" here: http://stackoverflow.com/questions/7928 ... collection
HTH,
Paul.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 4 guests