Java automatically manages memory with garbage collection.
In Java, memory is divided into stack (for method calls and primitives) and heap (for objects). The JVM automatically manages memory allocation and deallocation. Garbage Collection (GC) identifies and removes unused objects to free memory, preventing leaks. Developers can influence GC using references (weak, soft, strong) and by optimizing code, but they don’t directly free memory like in C/C++.
Average 5.0 by 1 learner