Skip to main content

Posts

Showing posts with the label Garbage Collection

Garbage Collection Interview Questions in Java

Garbage Collection 1.What is Garbage Collection in Java? Java has an internal mechanism called Garbage collection to reclaim the memory of unused projects at run time. Garbage collection is also known as automatic memory management. 2. Why Java provides Garbage Collector?   Java, there are no pointers. Memory management and allocation is done by JVM. Since memory allocation is automated, after some time JVM may go low on memory. At that time, JVM has to free memory from unused objects. To help with the process of reclaiming memory, Java provides an automated process called Garbage Collector. 3.What is the purpose of gc() in Java? Java provides two methods System.gc() and Runtime.gc() to request the JVM to run the garbage collection. By using these methods, programmers can explicitly send request for Garbage Collection. But JVM process can reject this request and wait for some time before running the GC. 4.How does Garbage Collection work in Java? J...