Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

Question about objects eligible to GC

Could you please explain why two and not one? I've made a diagram and got only one object without reference to the heap.

maybe I am missing something?

This is how I imagine that :

we are creating a, b and c objects. Then we are putting reference to b inside a.aob ( a.aob=b;), then put reference to a inside b.aob (b.aob=a;);

Then we are putting reference of a.aob to c.aob, (c.aob=a.aob;) which means we are putting reference to object b;

Then we are creating object d with A d=new A().aob=new A(); Maybe the problem is with this line of code? Is d initialized properly with such code?

Line c=b; mkes one object eligible to GC;

Line c.aob=null; simply makes inner reference of object b pointing to null;

So where is the second object eligible to GC?


I've possibly answered my question - adding additional parameter to constructor of class A made it clear as what object d is referencing after all:

A d=new A("first").aob=new A("second");

So d is referencing aob object, and the first object created gets eligible to GC at the very beginning.

Please tell me if I am still missing something!


Thank you in advance!

Your interpretation is correct. That statement can be easily understood by looking at the right-side operand, which is new A().aob = new A(); What it simply says is: create an object of A (the first new A()), and then take its aob variable, and then make it refer another object of A (the second new A()).

So we have two objects of A, and the aob of the first of these two objects refer the other object. So that's basically a couple of objects.


Now what's does this expression return (to the left-side operand)? It basically returns the second object of A, because that's the "value" being considered into this expression.


When you see several = operators in an expression, you can also evaluate it from right-to-left order. For instance, consider this:


int a = b = c.d = e;


What you first need to know is the value of 'e'. We put that value to c.d. And then we put whatever c.d contains to b. And then we put whatever b contains to a. At the end, a will have the value of e.


Does that give you some better insight?

And it looks like the tutoring service on your account is expired on May 06, 2016, which makes me unable to answer technical questions.

Do you like the service I provided to you so far, and want to extend the tutoring service?

Your assistance was very valuable for me, thank you!

I've got a lot of interesting stuff to consider and rethink from your detailed replies to my questions.

Thank you!


I will think about the opportunity of account prolongation.

Awesome! If you wish, here's the link: http://www.examlab.org/tutor/upgrade

I've passed the final exam - can I get some certificate for my results?


Thank you!

Just to make it sure - did you mean you pass the "Final exam" on examlab, or you passed the real Oracle exam?

On exam lab.

How to get prepared for the Oracle one?

We don't issue 'certificates' for passing the "final exam" on examlab - simply because passing exams on examlab (or any other practice tests) doesn't 'certify' you of anything. What examlab does is making you well-prepared for the Oracle exam.


You have already gone through all practice tests on examlab, so your next hurdle should be in taking the real Oracle exam, which will be your professional certification.


Based on the questions you have asked in the past, I can speculate that you are already prepared and everything is in order for you to take the real test. But that's only a speculation and you can only take it with your own risk.


Something more accurate than my words is Examlab's score predictor:

http://www.examlab.org/predictor


I can see, that it currently says you will score around 82% in the real exam, which is significantly above the passing score, so you should already be ready to go for the real exam!


Do you have a specific exam version in the mind that you wish to take?

Hi!

Thank you for the reply!

By exam version you mean jdk version?

Mainly, yes! But each exam has its own set of objectives.

Please take a look at OCPJP versions to determine which certification to go for...

ExamLab © 2008 - 2024