JVM Garbage collection uses Mark and Sweep algorithm to determine which objects are no longer in use. JVM runs this algorithm intermittently.

Read more http://codingthis.com/languages/java/demystifying-memory-management-java/