hi, Garbage collection cannot be forced.But we can make an object available for garbage collection by (1)setting the object reference to null (2)by calling the method System.gc or Runtime.getRuntime.gc() We cannot cause garbage collection to run at any point
If System.gc( ) is called, it will finalized and destroy all the objects that are no longer in use but only that time when gc runs. If you do not call System.gc( ), then only some of the objects will be finalized. The question when gc runs nobody knows even you call System.gc( ). Anyway it will probably run when there's low memory resources. correct me if i said anything wrong. Thanks.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop