SCJP 1.6 96%
Gil Steidle wrote:Question from Exam Lab's Java Programmer 6.0
How many objects are eligible for garbage collection after c.aob=null?
The correct answer is 2. I can only find but 1.
The A() object that was created by c=new A() is the one that I found as eligible for gc.
Thanks,
Gil
Jurica Krizanic - Java developer, OCPJP6, Spring Core certified developer!
Neha Daga wrote:You should search the forum before posting a question, It has been asked before.
For now, I can give you an explaination:
c.aob = a.aob and a.aob =b so effectively, c.aob = b.
So when c.aob = null means b = null now b also has and object b.aob which will also be eligible for gb if b is nulled.
So, there are two objects one referred by 'b' and one that is referred by 'b.aob'.
HTH
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Hareendra Reddy wrote:Hello all...
Actually 2 objects are garbage collected.
carefully look at this code..
Here object created in the first assignment expression is lost ,it's instance variable is in turn assigned a new object which is stored in d.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Hareendra Reddy wrote:ease up jackzia, actually second part of your code is different ...
here d refers to the new object created but in the original statements this object is lost but it's instance variable of same type is
assigned reference to the yet another object and also to d.
We can imagine original code like this...
Hareendra thanks!... I am usually eased up...Its just that sometimes when I think I got it right,
something new 'pops-up' and says "wait a minute! we arent done yet"...This is Java...
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:
Hareendra Reddy wrote:ease up jackzia, actually second part of your code is different ...
here d refers to the new object created but in the original statements this object is lost but it's instance variable of same type is
assigned reference to the yet another object and also to d.
We can imagine original code like this...
Hareendra thanks!... I am usually eased up...Its just that sometimes when I think I got it right,
something new 'pops-up' and says "wait a minute! we arent done yet"...This is Java...
Harrendra Take A look at the following...
SOURCE: ExamLab
Can you guess how many objects are ELIGIBLE for GC?? My answer is none! lol
I always use pencil and paper to sketch the heap and references to the heap
And I noticed that gab2.g can reference gab1 AND gab3 respectively.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Ikpefua Jacob-Obinyan wrote:
Harrendra Take A look at the following...
SOURCE: ExamLab
Can you guess how many objects are ELIGIBLE for GC?? My answer is none! lol
I always use pencil and paper to sketch the heap and references to the heap
And I noticed that gab2.g can reference gab1 AND gab3 respectively.
OCPJP 6 96%
Muneeswaran Balasubramanian wrote:
In the code the line no 11,
c=b;
c points to the object b.Then how c.aob=null makes b = null?
i think its make only b.aob=null
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Cheers Munees
My Blog
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
In your explanation diagram, you have mentioned the line 22 makes the null reference,How it makes that?
A d = new A().aob=new A()
I think the above line makes the reference d refers the object A thru only the object A.aob.Then how you make it as null reference in line 22.
Cheers Munees
My Blog
Muneeswaran wrote:
I "think" the above line makes the reference d refers.....
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara wrote:
In this particular statement, reference d is assigned whatever referred be the new A().aob, in this case the object created by the right most part of that statement (new A()). Here the intermediary object (which is created by the middle part) is abandoned, that is there's no live reference from the program pointing to it.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Ikpefua Jacob-Obinyan wrote:@Vijitha this is a very simple and CLEAR explanation...
...that people understand BETTER when you provide DETAILED sample programs and draw a diagram like I did above
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Consider Paul's rocket mass heater. |