wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collector......output.....? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "garbage collector......output.....?" Watch "garbage collector......output.....?" New topic
Author

garbage collector......output.....?

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
this is from esnips


Given the following code, how many objects will be eligible for garbage collection on the line with the comment //here

answer is:no object is eligible.

here two objects created for x and y.changes in method will not modify these objects.so up to now no object is eligible.

In line1 z is pointing to the object which is refered by y.
In line2 z is unreferenced.so one object is eligible.

can you explain line1 and line2?
[ November 02, 2008: Message edited by: Ganeshkumar cheekati ]

SCJP5 and SCWCD1.5
Think Twice Act Wise...
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833



It's the reference you are making null. What about the y reference? Still the object (created with the value 99) is referenced by y.
[ November 02, 2008: Message edited by: Vijitha Kumara ]

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
Hi



In line1, we are doing is that, just giving a new refenrce, z, to the object referred by y. so both y and z are pointing to the same object. In line2, we are assigning the refernce, z to null. ie, only changing the refernce, z. Still, y is pointing to the object. So, this won't be available for garbage collection. So the answer will be right.


Thanks<br /> <br />Anoobkumar<br />SCJP 1.5
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17



I have changed the code a little bit. When you set yy to null, it has no effect on y. So y refers to the integer object with value 99 and x refers to integer object with value 10 when the statement in question is reached.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
yeah i got it .
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

this is from esnips


The site being quoted is a filesharing site -- and cannot be used to validate a source. Filesharing sites do not check validity -- in fact, it has been know to share copyrighted materials.

Please do not quote from this site again -- as it will be treated as without a quote, and may have to be removed.

Henry
[ November 03, 2008: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: garbage collector......output.....?