when r we using garbage collection? and finalize()? we have to manually run it? Or, the system will do it automatically? I feel confuse on this section, pls help
Well, a programmer NEED NOT to call the gc explicitely, because , the JVM will automatically call the gc once it is conviced that a particular object cannot be accessed. However, you can suggest the JVM to invoke the gc by calling the <code>system.gc() or Runtime.getRuntime().gc()</code>. Same is the case for <code>finalise() </code> method. The API decalres that it is a protected method so in order to invoke this method you need to import java.lang.*; package. This method is invoked when the a method is being is eligible for gc, the programmer can override the finalise() method, inorder to do some cleaning up. But, one thing must be borne in mind that the programmer should not assume that by calling the method will run the method at that point in time. So no judgement should be made on this point. Hope this clears your doubt. Ravindra Mohan. [This message has been edited by Ravindra Mohan (edited May 30, 2001).]
Thanks for ur reply Ravindra!! I got a senario that might need ur help again For example, i had written down a program which consists of finalize() method on 1/2/01. Some how, at 1/5/01 the gc is going to occur. From my understanding, the finalize() method is called just before garbage colection. So, in this case... will the finalize() method that i created on 1/2/01 be executed on 1/5/01 ? (before the gc) Pls enlighten me....
[This message has been edited by jiny tee (edited June 05, 2001).]