• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Objects available for GC

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
mohammad shaid
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Devaka's ExamLabSimulator

I edited and made my own code

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit Garg Zindabad
Perfect Explanation
 
Devaka Cooray
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
mohammad shaid
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea.. got it prasad.. Thanks
 
Devaka Cooray
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:"Zindabad" is a hindi word


Not an Urdu word?
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to Devaka Sir

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





 
Ranch Hand
Posts: 30
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is not V
that is downward arrow
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for mistaking the downward arrow as V. Thanks for your response
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic