doubt on garbage collection

How the garbage collection thread is called.
Who calls the garbage collection thread. Is it jvm itself.
Is it called by jvm when ever we start running a program.
And when we say that garbage collection is an automatic process then why do we implement

System.gc()

in our code time to time.It should not make any sense if garbage collection runs on its own and if the garbage collection can not be forced.
Kindly explain.

The garbage collector is called by the JVM whenever it is needed, and possibly periodically, otherwise. The gc() method is simply a request to the JVM to call the GarbageCollector, but ionly that, a request. It does not guarantee that the GarbageCollector will be run, or, if it is, that it will be run immediately.

commented: Looks like you're on a roll tonight =) +4

in other words, don't doubt the garbage collection mechanism. It works well and there is no need to secondguess it by trying to force it to run.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.