What is Java Garbage Collection? Summary of Mark and Sweep, Young, Old, Perm concepts
When doing Java programming, you often hear the term Garbage Collection. Although development is possible without this knowledge in the early stages of development, it is good to know to optimize performance or prevent memory leaks.
This is one of the topics frequently asked in interviews at companies that use Java.
In this document, we will summarize Java Garbage Collection so that you can easily understand it.
This is a brief summary to help you understand unknown concepts, so we recommend that you read other articles for detailed information.
The name Garbage Collection means collection of garbage. Automatically collects unused memory
Unused Memory: Memory that is no longer used.
Memory Collection: Frees up unused memory so it can be used again.
Java memory management is done through JVM.
In existing languages, the programmer had to handle memory allocation and deallocation directly. If memory is not released properly, unused memory continues to accumulate and a memory leak occurs.
JVM is a virtual machine, processes memory allocation and deallocation automatically without the user having to worry
Specify the memory size to be used by the JVM by giving a JVM option when running the program.
Memory leak at the OS level is prevented by not directly accessing the OS level memory.
Garbage Collection secures memory by removing unreachable objects from the heap area
unreachable object: an object that is no longer referenced