Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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
reply
    Bookmark Topic Watch Topic
  • New Topic