The Java garbage collector runs as a separate thread, and will generally run when the system is otherwise quiet.

It is possible to prod the garbage collector into running immediately, but this should not normally be done.