• 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

force garbage collection?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had picked up some sentences from the Java Tutorial(from sun's website),
1. "You can ask the garbage collector to run at any time by calling System's gc method: System.gc();"
2. "The Java runtime system performs memory management tasks for you. When your program has finished using an object, that is, when there are no more references to an object, the object is finalized and is then garbage collected. These tasks happen asynchronously in the background. However, you can force object finalization and garbage collection using the appropriate method in the System class."
many people in this forum had said that gc can't be forced,so how to explain these sentences.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..
well.. the fact is that GC CANNOT BE FORCED and htere are no two ways about that.
A call to System.gc() or Runtime.gc() only SUGGESTS to the JVM that the garbage collector should be run. You never know when it will be run or indeed, if it will be run at all.. since teh garbage collector runs as a low-priority thread in teh background, u can never be sure when an object will be GCed or if it will be GCed at all..
hope this helps...
------------------
Hima
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic