Home           J2EE Concepts           JMS           Java Language           Contact           Back           Next           Bookmark this Page          










Some useful tips related to:
 - health & fitness
 - vehicle care
 - cooking
 - misc household tasks

Overview


Garbage Collector is an asynchronous memory management process that is executed by JVM in background to free up unused memory space that is being occupied by unused objects. Unused memory locations include:
- Memory locations that have never been used (& won't be used after)
- Objects that are no longer required or no longer referred from any where. For e.g. variables declared inside a method would be of no use once that method has been executed.
- Objects that have been declared by the program ready to be garbage collected (by calling finalize method)

How to call Garbage Collector?


The answer: Call System.gc()

However, issuing System.gc() doesn't mean that system would start performing garbage collection immediately. Yes, you read it correctly. Typically, this command makes a request to system to perform Garbage Collection; but it doesn't guarantee that objects that are no more being referred would be garbage collected immediately.

In fact, if your program is dependent on outcome of system.gc(), then probably you need to reconsider the design.