aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection  Exam LAb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection  Exam LAb" Watch "Garbage Collection  Exam LAb" New topic
Author

Garbage Collection Exam LAb

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

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





OCPJP 6.0 93%
OCPJWCD 5.0 98%
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

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

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

i am still confused Prasad Kharkar

Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Garbage Collection Exam LAb