Explain how to force garbage collection.Garbage collection can't be forced, it can explicitly be called using System.gc(), but there is not guarantee that GC will be started immediately.Does garbage collection guarantee that a program will not run out of memory?Garbage collection does not guarantee that a program will not run out of memory. The garbage collection is dependant on the JVM. Hence it is possible for the resources to be used faster than they are garbage collected. Garbage collection cannot be predicted if it will happen or not.Does garbage collection guarantee that a program will not run out of memory?Programs can in general create objects (that are not subject to garbage collection) and use memory resources faster than they can be garbage collected. Hence, Garbage collection does not guarantee that a program will not run out of memory.
|