A:
|
First, remember that the garbage collector works automatically,
whether you request it to or not. As it turns out, you cannot force
the garbage collector to run.
However, you can request the garbage collector to perform work,
by invoking the System.gc() method. This request may be processed by the
VM immediately, but it may not. Once working, you may experience a
short pause while the garbage collector does its work. That means that
if you want to manually run the garbage collector for some reason, you
should do it at an appropriate time, such as before a big task or when
the GUI is idle and waiting for input.
|