• 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 collection

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This Question is taken from K&B mock exam

Question: How many objects are eligible for Garbage collection after line 6.

The answer is 1. It says the only object without a reference is the one instantiated in line 4

My question is though the reference variable x2 is assigned to a different object in line 6. We still have the object at line 11 referenced by mx. How does that object becomes eligible for GC?

Thanks,
vijaya
[ August 26, 2004: Message edited by: vijaya dev ]
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Vijaya,

mx is a method-local variable and so will not exist as soon as the method ends. Always, the life of local variables are within the method only.

Hope that clears your doubt,
Kits
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey, I recognize that question!
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think line 6 is wrong, it should be
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic