• 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

Island of Isolation

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, when it comes to practising "garbage collection" concepts, is there anyway we can verify which objects have been garbage collected (say via System.out.println or something equivalent)?

The following code is to test if the objects have been garbage collected before the main method ends:



My current understanding is the makeObj() method created ObjA.


ObjA has a reference of type ObjB (named b) which points to the ObjB created by ObjA.


ObjB in turn, points to ObjA. But nothing else points to this two objects (they point to each other). Therefore they can be garbage collected.


So are these two objects eligible for garbage collection after the makeObj method ends or after the main method ends?
[ July 22, 2006: Message edited by: Shanel Jacob ]
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the only reference to ObjA object through the live code is the reference 'test' inside the method makeobj(). As soon as the method ends, the reference ceases to exist and hence both the objects are eligible for GC.

If makeObj would have returned an objA reference, then the two objects would have become eligible for GC only after the completion of main method.
[ July 22, 2006: Message edited by: Neelesh Bodas ]
 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Neelesh
 
reply
    Bookmark Topic Watch Topic
  • New Topic