Hi,
This is a method to ask the system to perform the garbage collection. Garbage collection is the process of cleaning up objects that don't have no references left, thus freeing up memory.
Normally this is handled fully automatically and you shouldn't ask this explicitly. But, because it's a time consuming process, you can call it on a moment your program has nothing else to do.
Also note that this only makes a suggestion towards the system. Nothing guarantees the garbage collection is actually done.
Thanks for your reply, but, I still have one more question.
I am writing a program which invokes a thread to scan for a file in a folder, if that file is present, it will do some processing otherwise goes to sleep.... I am using several arrays and string buffers during the processing. I want to call gc() just before the thread goes to sleep.. My question is if call gc(); would it automatically clear all the arrays and the buffers?
No. Garbage collection is not clearing the contents of an array or a buffer. It is removing the arrays completely - and only if there are no more references left towards the array or buffer.
And, as I told before, there is no guarantee whatsoever that the memory is freed at that time. I don't recommend using System.gc() yourself.