In computer science, garbage collection is the process of automatically freeing up memory that is no longer needed by a program. When a program creates objects or data structures in memory, the memory they occupy needs to be released when they are no longer needed, otherwise, the program can run out of memory and crash.
Garbage collection works by periodically scanning the memory of a program and identifying objects that are no longer referenced by the program. These objects are then considered "garbage" and can be safely deleted to free up memory.
For example, let's say you create a new object in your program:
person = { name: "John", age: 30 }
This object is stored in memory and takes up some space. If you no longer need this object, for example, if you delete the reference to it:
person = null
The object is no longer accessible by the program and becomes garbage. Garbage collection will then identify this object as garbage and free up the memory it occupied.
Another example would be if your program creates a large array:
bigArray = new Array(1000000)
This array takes up a lot of memory, but if you only use it briefly and then no longer need it, garbage collection can identify it as garbage and free up the memory it occupies.
Overall, garbage collection helps to manage memory usage in a program and prevent memory leaks or crashes due to running out of memory.
"Stop-the-world" is a term used to describe a particular phase or behavior of some garbage collection algorithms. During the stop-the-world phase, the garbage collector halts the execution of the application so that it can safely scan and clean up memory without interference from the running program. This pause is necessary because the garbage collector needs to ensure that no new memory allocations or deallocations are happening while it's identifying and reclaiming unused memory.
However, stop-the-world events can have a negative impact on the performance of the application. The length of the pause depends on the size of the memory heap and the complexity of the objects within it. Longer pauses can lead to decreased responsiveness and a degraded user experience, especially in real-time or latency-sensitive applications.
To address these issues, modern garbage collection algorithms have been developed that aim to minimize the impact of stop-the-world events. These include:
Generational garbage collection: This approach divides the memory heap into multiple generations based on the object's age. Younger objects are collected more frequently, while older objects are collected less often. This reduces the amount of memory that needs to be scanned during each GC cycle, shortening the stop-the-world pause.
Incremental garbage collection: Instead of performing the GC in one go, incremental garbage collection breaks the process into smaller tasks that can be executed between application tasks. This helps to reduce the length of stop-the-world pauses by spreading the GC workload over time.
Concurrent garbage collection: In this approach, the garbage collector runs concurrently with the application, allowing both to execute simultaneously. This can significantly reduce the need for stop-the-world pauses, although it often requires more complex algorithms and can introduce some overhead.
Despite these advancements, stop-the-world events may still occur in some situations, and developers should be mindful of their potential impact on application performance.
GC 튜닝-필요-이유
GC 튜닝-스트링 대체, 로그 최소화
GC 튜닝-Old 영역과, New 영역의 GC 시간 소요 차이
GC 튜닝-Old 영역 크기 조절로 실행시간+ vs OOM Error 방지 중 택 1
GC 튜닝 기본 옵션- 시작 시 영역, 최대 크기, New/Old 영역 비율
GC 튜닝 절차 - GC 상황 모니터링
https://d2.naver.com/helloworld/1329
https://www.digitalocean.com/community/tutorials/garbage-collection-in-java
JVM-GC-type-000-특징-객체 일시적으로 존재-두 가지 종류-Eden-000-may use bump-the-pointer ||&& thread-local allocation
JVM-GC-type-old-특징-young 생존자-major GC-uses card table
JVM-GC-Steps-000-old-types-serial GC-000-front heap remain-parallel GC-CMS GC-참조 끊긴 객체 식별