GC
What is GC?
Objects stored in the
Heaparea during Java runtime will continue to accumulate if not cleaned up, potentially causing anOutOfMemory ExceptionTo prevent this, the JVM periodically collects and cleans up unused objects through
Garbage Collection
Heap Area
A virtual memory space for storing objects
Stores objects and arrays created with the new operator
Heap Structure

young: Where relatively young references liveedenWhere freshly created references exist among the young generation
survivorTwo areas exist
Where references that survived eden temporarily reside
old: Where references that have survived a certain number of times residepermanent: Where metadata information from the method area is recorded
Minor GC and Major (Full) GC
GC is classified as
Minor GCorMajor GCdepending on the area where it is performed
Minor GCDeletes objects from the
Young Generation(Eden and Survivor 1, 2) areas from memory
Major GCAmong objects that were not deleted during the Minor GC process and were moved to the
Old Generationarea, those determined to be unused are deleted from memoryCauses
When the Old Generation area's memory is full and objects can no longer be allocated
When there are many objects in the Old Generation area that are no longer in use
When the application runs for a long time and objects in the Old Generation area are continuously created and destroyed
Cautions
When a Major GC occurs, the JVM stops application execution to perform GC, which is called the
Stop-the-WorldphenomenonSince all threads are stopped, no further work is executed, and performance degrades
It is important to ensure GC runs at an appropriate frequency to reduce Stop-the-World time and minimize the time threads are stopped
Last updated