Understanding Garbage Collection

What is Garbage Collection

Garbage collection is a process of automatically freeing memory that is no longer being used by a program.

Types of Garbage Collection

Serial GC: This is the most basic form of garbage collection and is used by default in most single-threaded applications.

Concurrent Mark and Sweep (CMS) GC

This type of GC is designed to be more concurrent than other types of GC, meaning that it can run while your application is still running.

When is Garbage Collected in Java

In Java, garbage is collected automatically. This means that when an object is no longer needed, the memory it occupies can be reclaimed by the system and used for other purposes.

How does Garbage Collection Work in Java

When an object is no longer reachable, the Java garbage collector runs and reclaims the memory associated with that object.

To get know more in formation on Garbage Collection