The garbage collector cannot ensure that there will always be enough memory.
The garbage collection (GC) algorithm varies from one JVM to another.
There are different algorithms being used, like reference counting or the mark and sweep algorithm.
Please google up for more insight to those algorithms.
To request garbage collection, you can call either of the following methods: