• 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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Please can someone help me clear up exactly how garbage collection works. I know it can't be forced, i know it runs in a low priority thread. I have created a mock question in which i cant work out when exactly the object ao becomes eligible for collection:
1 public void testMethod() {
2 AnObject ao = new AnObject();
3 AnObject other = new AnObject();
4 other = ao;
5 ao = null;
6 System.out.println("Other "+other);
7 }
Does ao become eligible after line 5 or when the method returns, or is it elsewhere...
Please help!
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
references do not get eligible for gc, objects do.
since the object held by ao is now referenced by other, it still is not eligible for gc.
but since they are local variables, once the method gets over at line 7, they are all eligible for gc.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic