How do I run the garbage collector to free memory and delete unused objects?
First, you should be aware that the garbage collector works automatically, whether you request it to or not. Secondly, you cannot force the garbage collector to run.
That said, you can request the garbage collector to perform work, by invoking the System.gc() method. Once working, you may experience a short pause while the garbage collector does its work. That means you should do it at an appropriate time, such as before a big task or when the GUI is idle and waiting for input.