This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection  Exam LAb" Watch "Garbage Collection  Exam LAb" New topic

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


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...


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

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

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Garbage Collection Exam LAb
It's not a secret anymore!