Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection Exam LAb

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Zhi Lin post:



After which line,is one object available for garbage collection ?

Correct answer:line10

But

In this code, the 'ags' of a1 is pointing to another Aegis object (lets call it X).

Now when a1 is made null, there is no meaning for a1.ags, right? which means that object X cannot be reached via a1.ags.

So, if I have the code as:


After Line 1, there are two objects eligible for GC, right?

another user posted the following to prove this...


Output:
Games
James

Can we said that when object reference a1 point to null, then its instance variable reference(a1.ags) will be set to null as well. Am I right?

Please correct, if i am wrong.

The post was left unanswered




 
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
suppose you have

then you say that if a1 is set to null then a1.ags will also be set to null
but this is not the case
still the object referred by a1.ags will b lost as we will not have any reference to the object referred by a1.ags
this is because we cannot ags also through a1 as a1 will now refer to null

hope this helps
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am still confused Prasad Kharkar

 
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
you look for the figure here
and think about that
even if it does not make sense to you
send me private message so that I will notice soon and I will look carefully into that and will draw figure on my own
and then I will post the figure on the forum
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic