Garbage Collection in Java
Garbage collection frees heap objects that nothing points to anymore. You don’t call free() like C++. The JVM decides when to collect.
System.gc() is only a hint, not a force. Memory leaks still happen if you keep unwanted references (static lists, caches).
Don’t say “Java has no memory problems”. GC helps; leaks are still possible.
Let's take this on the board with one tiny Main class — no extra files. Garbage Collection in Java — output: a is null; GC may collect the unused String. After a = null, no reference remains — GC can free it. Start from main, go line by line, and stop at each print. That output is the proof for Garbage Collection.
GC frees unreachable objects. You cannot force it. Leaks still possible if references remain.