File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection

 
maggie karve
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

answer is 2..i get 3....???
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup the answer is 2.

the objects referred by s1.a1.a2 and s1.a1.a2.a2 will be eligible for gc.

which other did you get???
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding Neha is right
 
rushikesh sawant
Ranch Hand
Posts: 65
 
saima kanwal
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone please explain how and what two objects are eligible for gc? I am really confused in this GC topic . I have seen the link referred above and have understood that example , but this one is really difficult. Anyone please explain.
 
maggie karve
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was considering the object referenced by s1.a1.a2.a2.a1..
According to me...

s1 is referring to an object..
.then s1.a1 will be further extension like
s1------->s1.a1
then s1=s1.a2,so they are referring to same object
then s1 or s1.a2---------->s1.a1.a2------------->s1.a1.a2.a2---------->s1.a1.a2.a2.a1;
Again due to
s1.a2.a1.a2=null;;
Since s1.a1=s1..i will refer this as s1.a1.a2 ok?
so s1.a1.a2 will be referring to null.......and hence further s1.a1.a2.a2 's object will not be referring to anything...so are "these" objects eleigible for Gc???
what about the object made by s1.a1.a2.a2.a1 since it is no longer pointing to its first object ..it is pointing to latest s1.a1's object.....???
thanks...

 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s1---------------> object A and it contains two reference variable a1 and a2 pointing to null at the moment
s1.a1---------------> another object A that again contains two reference variable a1 and a2 pointing to null at the moment
s1.a2 = s1 ---------> means s1.a2 points to object refered by s1.
s1.a1.a2-------------> yet another object A that contains two reference variable a1 and a2 pointing to null at the moment.
s1.a1.a2.a2------------> yet another object A that contains two reference variable a1 and a2 pointing to null at the moment.
s1.a1.a2.a2.a1=s1.a1-------> means both of them point to same object which was s1.a1 was pointing.
s1.a2.a1.a2=null----------> means object refered by s1.a1.a2 becomes null (since s1 and s1,a2 refers to same object there a1 reference variable is same)
so now object refered by s1.a1.a2 has no live reference and hence object refered by s1.a1.a2.a2 also loses any live references.
and hence these 2 objects become eligible for gc.


I hope this helps.
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saima kanwal wrote:can anyone please explain how and what two objects are eligible for gc? I am really confused in this GC topic . I have seen the link referred above and have understood that example , but this one is really difficult. Anyone please explain.


the best way to solve gc question is drawing a diagram.
 
saima kanwal
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks neha for your superb explanation!!
 
rushikesh sawant
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice explanation by neha, it must have helped.
 
seomul evans
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you neha for clarification
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic