JavaIntermediate#gc#memory

What is garbage collection?

Automatic memory management that reclaims heap memory occupied by unreachable objects. Generational GCs (Young, Old, Metaspace) use algorithms like G1, ZGC, Parallel. You can suggest collection with System.gc() but cannot force it.

Example
Person p = new Person();
p = null; // object now unreachable, eligible for GC
System.gc(); // hint to JVM, not guaranteed

Related Questions

1
JavaIntermediate#exceptions

What are checked vs unchecked exceptions?

Open
2
JavaBeginner#strings

What is the difference between String, StringBuilder, and StringBuffer?

Open
3
JavaIntermediate#strings

Why are Strings immutable in Java?

Open