This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Garbage Collection

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody let me know when an object is eligible for garbage collection with some examples?

Thanks in advance,
Malini
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Malini,

An object is said to be ready for garbage collection whenever it is not holding any references. The JVM may then execute the Garabge Collector "at will" and remove such unreferenced objects from memory.

Another scenario is when a gc may need to free up memory for other objects. At this time it may remove objects in a given order (depends on JVM), say in order of last usage time or if the object is holding weak references.

Finally, a developer may want to call gc at a specific time and thats where one uses calls to methods of the GC or System class explicitly.(ref api)

-- A coding best practice related to GC is to call the finalize method, wherein references held by objects, that are no longer in use can be released. Finalise method is executed just before gc completes execution. But beware that this method may not be called everytime so try using alternatives.

Lemme know if you need more details.
 
Let nothing stop you! Not even this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic