Calling gc() does
not explicitly execute the garbage collector. It suggests to the JVM that now would be a good time for some GC. The JVM may do a full GC, a bit of GC, or no GC at all, in response.
Some of your concerns are unfounded. Particularly, you will never get an OutOfMemoryError when there exist objects that could be garbage collected, and would free enough memory to allow execution to continue.
Tweaking the garbage collector is possible, to achieve better performance (for various definitions of "better"). However, it is an advanced topic (one that I am not all that expert in ). Only very rarely does it involve calling gc() - that's usually pointless. There is no direct way to change the GC thread priority, but you can adjust a variety of settings.
From the questions you are asking, I detect that you probably aren't at the stage where
you should be worrying about it. For 99% of simple
Java applications, the GC just happens and all is fine.
[ January 29, 2008: Message edited by: Peter Chase ]