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.
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