File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects available for GC

 
mohammad shaid
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
mohammad shaid
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Devaka's ExamLabSimulator

I edited and made my own code

 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg Zindabad
Perfect Explanation
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Kharkar wrote:Zindabad

Not everyone understand Hindi. At lease, I don't
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops.. sorry.. i got it.. one object initially gets GCed.. then the rest two... Thanks Ankit bro..
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops.. sorry.. it was prasad... so just got lost into solving this problem.. sorry prasad.. and thanks for correcting,, hehe
 
mohammad shaid
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
mohammad shaid
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.. got it.. got it.. didnt see that word GC.. Thanks prasad..
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea.. got it prasad.. Thanks
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Kharkar wrote:"Zindabad" is a hindi word

Not an Urdu word?
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Devaka Sir

Before reading this Topic even i dint knw that "Zindabad" is an Urdu word.





 
Sandy Ghosh
Ranch Hand
Posts: 30
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every thing is fine but line 4 must be

this.d = (Drag) d

Otherwise it won't complile....
 
Ankit Garg
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akila is there a specific line that's confusing you or the whole question??
 
Akil Kumar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is not V
that is downward arrow
 
Ankit Garg
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for mistaking the downward arrow as V. Thanks for your response
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic