| Author |
Objects available for GC
|
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
How do we trace down this particular example to get to know the number of objects available for GC???
I am having problem with how to draw the sketch of the objects as its not specified in books.. can someone help.. i got an exam on tuesday
|
Thanks & Regards,
shaad
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2691
|
|
|
Please QuoteYourSources.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
From Devaka's ExamLabSimulator
I edited and made my own code
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
Hello shaid
howz you?
well this code should give the compiler error because I compiled and checked
that is because in the constructor of the class we are passing the Drag object that takes the Object as parameter
that should be
well I did this and will try for GC issue now
as I am not sure whether I will be able to solve it to the perfection or not so I am not posting here
I am trying it now
well
Anikit sir got the answer
|
SCJP 6 [86%] June 30th, 2010
If you find any post useful, click the "plus one" sign on the right
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
At line 7 the memory structure looks like
At line 9, the memory structure looks like this
After Line 10, the memory structure looks like this
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
Ankit Garg Zindabad
Perfect Explanation
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2691
|
|
Prasad Kharkar wrote:Zindabad
Not everyone understand Hindi. At lease, I don't
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
we don't need to understand Hindi
Hailing Sanath Jaysuriya and Sachin Tendulkar can make our communications better
isn't it?
Hope Devaka sir are interested in Cricket
well is the word "hail" right
I mean to say praising Sachin and Jaysuriya will make our communications better
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2691
|
|
Seriously, in any case, JavaRanch is an English forum - all communication needs to be in English.
[Edit: My bad, I thought it's a Hindi word ]
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
Thanks a lot Satish for Correcting my code and Ankit sir for a very fantastic explanation.. thanks once again..
and i want to clear if the third object here is getting GCed??
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
|
oops.. sorry.. i got it.. one object initially gets GCed.. then the rest two... Thanks Ankit bro..
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
@ Devaka sir
I will definitely use only English for javaranch
and "Zindabad" is a hindi word
@ Shaad
who is satish here?
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
|
oops.. sorry.. it was prasad... so just got lost into solving this problem.. sorry prasad.. and thanks for correcting,, hehe
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
hey prasad i gt only 2 objects for GC .. which one's the third?
Is it the d1 object?.. i mean d2.d.d was made to refer to d1.d
so is the object that initially was referring to d1.d will get GCed as the last object?
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
|
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
|
got it.. got it.. got it.. didnt see that word GC.. Thanks prasad..
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
d2.d and d1.d.d are now pointing to the same object isn't it?
thus cancelling the link between object poited by d2 and object number 2
now 2 was referring to object referred by 1 but as 2 has no external reference
1 also does not have any reference
hence the object 1, 2 are eligible for GC and 3 was done already
hope this helps now
|
 |
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
|
|
|
yea.. got it prasad.. Thanks
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2691
|
|
Prasad Kharkar wrote:"Zindabad" is a hindi word 
Not an Urdu word?
|
 |
Sahil Kapoor
Ranch Hand
Joined: Sep 12, 2009
Posts: 316
|
|
Thanks to Devaka Sir
Before reading this Topic even i dint knw that "Zindabad" is an Urdu word.
|
SCJP 6.0 96%
(Connecting the Dots ....)
|
 |
Sandy Ghosh
Greenhorn
Joined: Jun 05, 2010
Posts: 26
|
|
Every thing is fine but line 4 must be
this.d = (Drag) d
Otherwise it won't complile....
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Sandy Ghosh wrote:Every thing is fine but line 4 must be
this.d = (Drag) d
Otherwise it won't complile....
Yes this has been pointed out before by Prasad...
|
 |
Akil Kumar
Ranch Hand
Joined: Jun 08, 2009
Posts: 83
|
|
Ankit,
I am still not able to correlate the program with the sketch. Can you please explain? I really appreciate your help.
Thanks
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Akila is there a specific line that's confusing you or the whole question??
|
 |
Akil Kumar
Ranch Hand
Joined: Jun 08, 2009
Posts: 83
|
|
Ankit,
I am not able to understand the whole question. While giving the exams I always get this kind of questions wrong. Sorry, you must have explained many times about this in this forum. This is what I inferred from the diagram
a. When you say d1 --> V, d2 ---> V you are referring to the instance variables
b. At line 7 it creates three new objects out of which one is passed null.
c. I am not understand the line 8
d. At line 9 again 3 objects gets created out of which the third one is passed with the reference d1.
e. At line 10 d2 is referring to d1.
I am not able to connect all these and find out how many objects are eligible for GC.
Thanks
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
I thnik that at code line 8, this is the memory structure. The last in our chain of elements now points to a new Drag(null) element. Please correct me if I'm wrong.
|
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
that is not V
that is downward arrow
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Akila Agandeswaran wrote:a. When you say d1 --> V, d2 ---> V you are referring to the instance variables
Well actually that V in my diagrams is supposed to mean an arrow. So when I draw this
It means that a is a reference variable. The | and V is the arrow (just like you drew ---> ). The box is the actual object to which the reference variable a points. I've drawn these types of diagrams so many times that I assume that everyone understands them. Anyways I hope you can understand the diagram better now.
Akila Agandeswaran wrote:b. At line 7 it creates three new objects out of which one is passed null.
Correct
Akila Agandeswaran wrote:c. I am not understand the line 8
Martin's diagram shows line 8 very well.
Akila Agandeswaran wrote:d. At line 9 again 3 objects gets created out of which the third one is passed with the reference d1.
Correct
Akila Agandeswaran wrote:e. At line 10 d2 is referring to d1.
No. Read it carefully. The line is d2.d = d1.d and not d2 = d1...
[Edit: beaten to the V thing]
|
 |
Akil Kumar
Ranch Hand
Joined: Jun 08, 2009
Posts: 83
|
|
|
Sorry for mistaking the downward arrow as V. Thanks for your response
|
 |
 |
|
|
subject: Objects available for GC
|
|
|