Java garbage collection

Garbage collection is the process of freeing storage that is used by objects that are no longer referred to by a program. With garbage collection, programmers no longer have to write error prone code to explicitly "free" or "delete" their objects. This code frequently results in "memory leak" program errors. The garbage collector automatically detects an object or group of objects that the user program can no longer reach. It does this because there are no references to that object in any program structure. Once the object has been collected, you can allocate the space for other uses.

The Java™ runtime environment includes a garbage collector that frees memory that is no longer in use. The garbage collector runs automatically, as needed.

The garbage collector can also be started explicitly under the control of the Java program using the java.lang.Runtime.gc() method.

Related concepts
Java event trace performance tools
Java performance considerations
Java Native Method Invocation performance considerations
Java method inlining performance considerations
Java exception performance considerations
Java call trace performance tools
Java profiling performance tools
Related tasks
Collect Java performance data