DEV Community

loading...
Cover image for Garbage Collection in Java - What is GC and How it Works in the JVM

Garbage Collection in Java - What is GC and How it Works in the JVM

theawesomenayak profile image Siben Nayak ・1 min read

Garbage Collection is the process of reclaiming the runtime unused memory by destroying the unused objects.

In languages like C and C++, the programmer is responsible for both the creation and destruction of objects. Sometimes, the programmer may forget to destroy useless objects, and the memory allocated to them is not released. The used memory of the system keeps on growing and eventually there is no memory left in the system to allocate. Such applications suffer from “memory leaks”.

Java Garbage Collection is the process by which Java programs perform automatic memory management. Java programs compile into bytecode that can be run on a Java Virtual Machine (JVM).

Garbage collection makes Java memory-efficient because it removes the unreferenced objects from heap memory and makes free space for new objects.

The Java Virtual Machine has many types of garbage collectors.

In these videos, I’ve discussed the Garbage Collection in Java, how it works, and the various types of collectors available.

Please subscribe to the channel and like the video if you find it helpful.

Discussion (0)

pic
Editor guide