Saturday, 9 March 2013

Interview Question #1 What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.Garbage collector is invoked automatically by JVM. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used and by  unreachable mean that there are no references of that object on the stack.You can also specify when to invoke garbage collector using System.gc() but it is not necessary that JVM will always invoke garbage collector on encountering this function.

Related Questions

No comments:

Post a Comment

t> UA-39527780-1 back to top