9.2.14. About Garbage Collection

Garbage collection is a form of automatic memory management provided by the Java Virtual Machine (JVM). Periodically, the garbage collector runs, and reclaims memory which was claimed by objects which are no longer in use by applications.
An object becomes eligible for garbage collection when there are no more references to it. In effect, this means that no threads refer to it anymore.
Garbage collection happens outside of user control. The JVM decides to run garbage collection based on the amount of available heap size. The heap size is tunable for performance. Refer to the documentation of your JVM for more information.