• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i got it .
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic